Skip to content

Instantly share code, notes, and snippets.

@lu-zero lu-zero/hello.rs
Created Sep 30, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.