Created
November 8, 2019 22:08
-
-
Save rust-play/95a3c5680d86ff9f06cda676e60ec395 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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