Created
September 21, 2015 13:55
-
-
Save scharfie/f169126b6b53826814a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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