LockedValueRef

Struct LockedValueRef 

Source
pub struct LockedValueRef<'a, T, L>
where L: LockValue<T>,
{ /* private fields */ }
Expand description

A reference to a value behind a lock.

This struct allows querying locked data without copying. The lock is acquired when needed and released when dropped.

Implementations§

Source§

impl<'a, T, L> LockedValueRef<'a, T, L>
where L: LockValue<T>,

Source

pub fn new(lock: &'a L) -> Self

Source

pub fn with_value<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&T) -> R,

Execute a function with access to the locked value.

Source

pub fn map<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&T) -> R,

Try to get a value from the lock by applying a function.

Source

pub fn matches<F>(&self, predicate: F) -> bool
where F: FnOnce(&T) -> bool,

Check if the locked value matches a predicate.

Auto Trait Implementations§

§

impl<'a, T, L> Freeze for LockedValueRef<'a, T, L>

§

impl<'a, T, L> RefUnwindSafe for LockedValueRef<'a, T, L>

§

impl<'a, T, L> Send for LockedValueRef<'a, T, L>
where L: Sync, T: Send,

§

impl<'a, T, L> Sync for LockedValueRef<'a, T, L>
where L: Sync, T: Sync,

§

impl<'a, T, L> Unpin for LockedValueRef<'a, T, L>
where T: Unpin,

§

impl<'a, T, L> UnwindSafe for LockedValueRef<'a, T, L>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.