Skip to content

Instantly share code, notes, and snippets.

@XanClic
Created January 26, 2022 16:38
Show Gist options
  • Save XanClic/ce1011507fb8197e399e7d7243941a60 to your computer and use it in GitHub Desktop.
Save XanClic/ce1011507fb8197e399e7d7243941a60 to your computer and use it in GitHub Desktop.
use std::ops::Deref;
struct T {
x: isize,
}
impl T {
fn from(x: isize) -> Self {
T { x }
}
}
impl Deref for T {
type Target = isize;
fn deref(&self) -> &isize {
&self.x
}
}
fn print_num(v: &isize) {
println!("{}", v);
}
fn main() {
let t = T::from(42);
print_num(&t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment