Skip to content

Instantly share code, notes, and snippets.

@scharfie
Created September 21, 2015 13:55
Show Gist options
  • Save scharfie/f169126b6b53826814a2 to your computer and use it in GitHub Desktop.
Save scharfie/f169126b6b53826814a2 to your computer and use it in GitHub Desktop.
use std::fmt;
struct NameBadge {
name: String
}
impl fmt::Display for NameBadge {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Hello, my name is {}", self.name)
}
}
fn main() {
let mut bob = String::new();
bob.push_str("Bob");
let badge = NameBadge {
name: bob
};
println!("Your badge reads: {}", badge);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment