Lock

Trait Lock 

Source
pub trait Lock<T> {
    // Required methods
    fn new(b: T) -> Self;
    fn into_inner(self) -> T;
    fn with_lock<R>(&self, f: impl FnOnce(&mut T) -> R) -> R;
}
Expand description

A type that allows mutable access to its inner value via interior mutability.

Required Methods§

Source

fn new(b: T) -> Self

Create a new instance of the lock.

Source

fn into_inner(self) -> T

Consume the lock and return the inner value.

Source

fn with_lock<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Perform an operation on the inner value by taking the lock.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> Lock<T> for RefCell<T>

Source§

fn new(b: T) -> Self

Source§

fn into_inner(self) -> T

Source§

fn with_lock<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Source§

impl<T> Lock<T> for Mutex<T>

Source§

fn new(b: T) -> Self

Source§

fn into_inner(self) -> T

Source§

fn with_lock<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Implementors§