I'm currently learnign rust by reading Beginning Rust by Carlos Milanesi.
I arrived at the example on page 269/270 and get an confusing error E0214 E0223 with the line "let mut person: Person::new();".
After trying to figure out what is wrong for some time now I give up and just want to know what is wrong with the code I typed into the editor:
fn main(){
struct Person {
personal_names: String,
family_names: String,
}
impl Person {
fn new() -> Self {
Self{
personal_names: String::new(),
family_names: String::new(),
}
}
fn naming(&self) ->String {
format!("{} {}", self.personal_names, self.family_names)
}
}
impl Person {
fn set_personal_names(&mut self, new_name: String) {
self.personal_names = new_name;
}
}
let mut person: Person::new();
print!("[{}] ", person.naming());
person.personal_names = "John".to_string();
person.family_names = "Doe".to_string();
print!("[{}] ", person.naming());
person.set_personal_names("Jane".to_string());
print!("[{}]", person.naming());
}