This simple function locks a f64
and updates the value
use std::sync::Mutex;
fn bar() {
let a = Mutex::new(1.0);
let mut b = a.lock().unwrap();
*b = 2.0;
foo(a, 3.0);
}
I would like to encapsulate the behaviour into a function but I cannot figure out how to specify the where
clause for T
fn foo<T, V>(lockable_param: T, value: V)
// where
// T: Mutex??,
{
let mut lock = lockable_param.lock().unwrap();
*lock = value;
}
.lock().unwrap()
? 2) How areV
andT
related, why are you trying to assign aV
where aT
would be expected? In your first example, bothT
andV
seem to be the same typef64
. – Andrey Tyukin