cannot move out of borrowed content


#1

my code is here:

let no_user = User {
                id: 0,
                email: "".to_owned(),
                username: "".to_owned(),
                password: "".to_owned(),
                created_at : SystemTime::now(),
        };
        match login_user {
            Some(login_user) => {
                match verify(&signin_user.password, &login_user.password) {
                    Ok(valid) => {
                        let user_id = login_user.id.to_string();
                        let token = token::generate_token(user_id).unwrap();
                        Ok(SigninMsgs { 
                            status: 200,
                            token: token,
                            signin_user: *login_user,
                            message : "Succesfully signin.".to_string(),
                        })
                    },
                    Err(_) => {
                        Ok(SigninMsgs { 
                            status: 400,
                            token: "".to_owned(),
                            signin_user: no_user,
                            message : "Incorrect Password.".to_string(),
                        })
                    },
                }
            },
            None => {
                Ok(SigninMsgs { 
                        status: 400,
                        token: "".to_owned(),
                        signin_user: no_user,
                        message : "Signin failure.".to_string(),
                })
            }
        }

when ‘cargo run’ , I get the error:

error[E0507]: cannot move out of borrowed content
  --> src/handler/func.rs:78:42
   |
78 |                             signin_user: *login_user,
   |                                          ^^^^^^^^^^^ cannot move out of borrowed content

error: aborting due to previous error

How can i get the ‘login_user’ ?


#2

Which type is login_user?
Try signin_user: (*login_user).clone(),


#3

Just login_user.clone() should be good - no need to deref it explicitly (the clone method call will do it automatically). But yeah, more context to the code would help.

Separately, no_user might be better represented as a None, where user is stored as Option<User>.