I have this static element:
pub static CREDENTIALS: Mutex<DatabaseCredentials> = Mutex::new(DatabaseCredentials::new());
and I want to take the content out of the Mutex:
let creds = CREDENTIALS.into_inner().unwrap().clone();
and I am getting this error:
let creds = CREDENTIALS.into_inner().unwrap();
| ^^^^^^^^^^^ move occurs because `CREDENTIALS` has type `std::sync::Mutex<connection::credentials::DatabaseCredentials<'_>>`, which does not implement the `Copy` trait
Where my DatabaseCredentials looks as follows:
#[derive(Clone, Copy)]
pub struct DatabaseCredentials<'a> {
pub username: &'a str,
pub password: &'a str,
pub host: &'a str,
pub db_name: &'a str
}
unsafe impl Send for DatabaseCredentials<'_> {}
unsafe impl Sync for DatabaseCredentials<'_> {}
// impl block...
How can I get rid out of the error, and take the underlying value inside the Mutex?