Skip to main content

Mutex

Struct Mutex 

Source
pub struct Mutex<T> { /* private fields */ }

Implementations§

Source§

impl<T> Mutex<T>

Source

pub const fn new(content: T) -> Self

Create a new mutex

Source

pub unsafe fn locked(content: T) -> Self

Create a new mutex that is already locked. This is a more efficient way to do the following:

let mut mutex = Mutex::new(());
mutex.manual_lock();
Source

pub unsafe fn manual_try_lock(&self) -> Result<&mut T, c_int>

Tries to lock the mutex, fails if it’s already locked. Manual means it’s up to you to unlock it after mutex. Returns the last atomic value on failure. You should probably not worry about this, it’s used for internal optimizations.

Source

pub unsafe fn manual_lock(&self) -> &mut T

Lock the mutex, returning the inner content. After doing this, it’s your responsibility to unlock it after usage. Mostly useful for FFI: Prefer normal .lock() where possible.

Source

pub unsafe fn manual_unlock(&self)

Unlock the mutex, if it’s locked.

Source

pub fn as_ptr(&self) -> *mut T

Source

pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>

Tries to lock the mutex and returns a guard that automatically unlocks the mutex when it falls out of scope.

Source

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

Locks the mutex and returns a guard that automatically unlocks the mutex when it falls out of scope.

Trait Implementations§

Source§

impl<T: Send> Send for Mutex<T>

Source§

impl<T: Send> Sync for Mutex<T>

Auto Trait Implementations§

§

impl<T> !Freeze for Mutex<T>

§

impl<T> !RefUnwindSafe for Mutex<T>

§

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

§

impl<T> UnsafeUnpin for Mutex<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Mutex<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
§

impl<T> CastSlice<'_, T> for T

§

fn cast_slice(selves: &[T]) -> &[T]

§

impl<T> CastSliceMut<'_, T> for T

§

fn cast_slice_mut(selves: &mut [T]) -> &mut [T]

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> Same for T

Source§

type Output = T

Should always be Self
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.