Skip to content

Instantly share code, notes, and snippets.

@Steboss89
Created June 9, 2021 08:47
Show Gist options
  • Save Steboss89/9649ed0d9165326ecef0a8d8fdf0c17d to your computer and use it in GitHub Desktop.
Save Steboss89/9649ed0d9165326ecef0a8d8fdf0c17d to your computer and use it in GitHub Desktop.
Trait with inherent implementation
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