Skip to content

Instantly share code, notes, and snippets.

@lu-zero
Created September 30, 2019 08:45
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 lu-zero/6eb8a9a715105d471fb4cc6cca3176ab to your computer and use it in GitHub Desktop.
Save lu-zero/6eb8a9a715105d471fb4cc6cca3176ab to your computer and use it in GitHub Desktop.
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