[][src]Function padlock::mutex_lock

pub fn mutex_lock<T, F, R>(m: &Mutex<T>, f: F) -> R where
    F: FnOnce(&mut T) -> R, 

Aquire a Mutex lock, passing the lock to the lambda. The lock is released when the lambda finishes. This function returns whatever the lambda returns, allowing you to extract data from a lock without having to worry about releasing the lock.

Read:

This example is not tested
let extracted = padlock::mutex_lock(&arc_mutex_var, |lock| lock.clone());

Write:

This example is not tested
padlock::mutex_lock(&arc_mutex_var, |lock| *lock = new_value);