Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 8, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/95a3c5680d86ff9f06cda676e60ec395 to your computer and use it in GitHub Desktop.
Save rust-play/95a3c5680d86ff9f06cda676e60ec395 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn foo<T : std::convert::Into<usize>>(d : &T) -> usize {
d.into()
}
struct Bar {
a : usize
}
impl std::convert::Into<usize> for Bar {
fn into(self) -> usize {
self.a
}
}
fn main() {
let bar = Bar { a : 15 };
assert!(foo(&bar) == 15);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment