Last active
August 22, 2019 11:11
-
-
Save sebastianfrelle/d9b20981388cd599b3ce481bda4cea17 to your computer and use it in GitHub Desktop.
Greeting between two people
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
trait Greetable { | |
fn greeting_for_other(&self, other: &Self) -> String; | |
} | |
struct Person<'a> { | |
name: &'a str, | |
age: u8, | |
} | |
impl<'a> Greetable for Person<'a> { | |
fn greeting_for_other(&self, other: &Self) -> String { | |
return format!( | |
"Hi, {}; I'm {}, and I'm {} years old!", | |
other.name, self.name, self.age | |
); | |
} | |
} | |
fn main() { | |
let p1 = Person { | |
name: "Sebastian", | |
age: 25, | |
}; | |
let p2 = Person { | |
name: "Simon", | |
age: 24, | |
}; | |
let s = p1.greeting_for_other(&p2); | |
println!("{}", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment