Created
June 9, 2021 08:47
-
-
Save Steboss89/9649ed0d9165326ecef0a8d8fdf0c17d to your computer and use it in GitHub Desktop.
Trait with inherent implementation
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
struct Person { | |
name: String, // NB there's a comma here | |
surname: String, | |
age: u32 | |
} | |
// notice now we are defining impl METHOD for TYPE | |
impl WhoAreYou for Person { | |
fn who_are_you(&self) -> String{ | |
return format!("Person name is {} surname {} and age {}", self.name, self.surname, self.age); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment