Ad
Code
Diff
  • struct Person {
      first_name: String,
      last_name: String,
    }
    
    impl Person {
        fn new(first_name: String, last_name: String) -> Self {
            Person {first_name, last_name}  
        }
        
        fn greet(&self) -> String {
            format!("Hello, my name is {} {}", self.first_name, self.last_name)
        }
    }
    • struct Person {
    • first_name: String,
    • last_name: String,
    • }
    • impl Person {
    • fn greet(&self) -> String {
    • format!("Hello, my name is {} {}", self.first_name, self.last_name)
    • }
    • }
    • fn person_builder(first_name: &str, last_name: &str) -> Person {
    • Person { first_name: first_name.to_owned(), last_name: last_name.to_owned() }
    • fn new(first_name: String, last_name: String) -> Self {
    • Person {first_name, last_name}
    • }
    • fn greet(&self) -> String {
    • format!("Hello, my name is {} {}", self.first_name, self.last_name)
    • }
    • }