I got this error:
--> src/client.rs:189:22
|
189 | let client = client.clone().lock().unwrap();
| ^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary which is freed while still in use
on this function that is too big for me to post a minimum reproducible example:
async fn send_and_expect<T: OnEvent<T>>(
client: Arc<Mutex<Self>>,
request: rtsp_types::Message<Body>,
unauthorized_retry: i32,
) -> std::result::Result<rtsp_types::Response<Body>, ClientActionError>
where
RtspMachine: OnEvent<T>,
T: From<Response>,
{
let expected_cseq = client_parse_cseq(&request)?;
let mut client = client.lock().unwrap();
If I simply not clone, that is, do let mut client = client.lock().unwrap();, it compiles. But I was wondering why clone() makes this error happen.
I tried to reproduce the problem to post here:
use std::sync::{Arc, Mutex};
fn main() {
let a = Arc::new(Mutex::new(0));
a.clone().lock().unwrap();
}
but this compiles ok.
What is wrong? Why would client.clone() sometimes be freed before finishing using it but sometimes not?