Struct OnceMutex

Source
pub struct OnceMutex<T> { /* private fields */ }
Expand description

A mutex which can only be locked once, but which provides very fast, lock-free, concurrent reads after the first lock is over.

Implementations§

Source§

impl<T: Send + Sync> OnceMutex<T>

Source

pub fn new(x: T) -> OnceMutex<T>

Create a new OnceMutex.

Source

pub fn lock(&self) -> Option<OnceMutexGuard<'_, T>>

Attempt to lock the OnceMutex.

This will not block, but will return None if the OnceMutex has already been locked or is currently locked by another thread.

Source

pub fn wait(&self)

Block the current task until the first lock is over.

Does nothing if there is no lock.

Source

pub fn into_inner(self) -> T

Extract the data from a OnceMutex.

Source

pub fn locked(&self) -> bool

Is this OnceMutex currently locked?

Trait Implementations§

Source§

impl<T: Send + Sync> Deref for OnceMutex<T>

Source§

fn deref(&self) -> &T

Get a reference to the value inside the OnceMutex.

This can block if the OnceMutex is in its lock, but is very fast otherwise.

Source§

type Target = T

The resulting type after dereferencing.
Source§

impl<T: Send + Sync> DerefMut for OnceMutex<T>

Source§

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

Mutably dereferences the value.
Source§

impl<T: Send> Send for OnceMutex<T>

Source§

impl<T: Sync> Sync for OnceMutex<T>

Auto Trait Implementations§

§

impl<T> !Freeze for OnceMutex<T>

§

impl<T> !RefUnwindSafe for OnceMutex<T>

§

impl<T> Unpin for OnceMutex<T>
where T: Unpin,

§

impl<T> UnwindSafe for OnceMutex<T>
where T: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.