Created
September 30, 2019 08:45
-
-
Save lu-zero/6eb8a9a715105d471fb4cc6cca3176ab to your computer and use it in GitHub Desktop.
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
use std::fmt; | |
struct Foo { | |
a: usize, | |
} | |
impl fmt::Display for Foo { | |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
write!(f, "{}", self.a) | |
} | |
} | |
fn say_hello<T: fmt::Display>(who: T) { | |
println!("Hello {}", who); | |
} | |
fn main() { | |
let a = Foo { a: 42 }; | |
say_hello("world"); | |
say_hello(&a); | |
say_hello(a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment