Why derefrence happening inside this replace() method?

fn main(){
    let mut person1 = Person::Details{name: "jake".to_string(), id:12, subject: Subject::English};
    person1.replace("sam".to_string(), Subject::English );
    println!("The person is {:?}", person1);
}
#[derive(Debug)]
enum Person{
    Details{ name:String, id:u32, subject:Subject}   
}
#[derive(Debug)]
enum Subject{
    Maths,
    English
}

impl Person{
    fn replace(&mut self, target:String, target1:Subject){
       match self{
        Person::Details { name, id, subject } =>{
            *name = target;
        }
       }
    }
}

Here, why i need a deref operator for name, inorder to change the name value ?

When the value you are matching on is a reference, all pattern bindings within the match branch will be references as well.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.