Skip to main content

MaybeMut

Enum MaybeMut 

Source
#[repr(C)]
pub enum MaybeMut<'mem, 'facet> { Not(Peek<'mem, 'facet>), Mut(Poke<'mem, 'facet>), }
Expand description

Some reference to a type that implements Facet that may be mut or not.

Variants§

§

Not(Peek<'mem, 'facet>)

§

Mut(Poke<'mem, 'facet>)

Implementations§

Source§

impl<'mem, 'facet> MaybeMut<'mem, 'facet>

Source

pub fn as_peek(&'mem self) -> Peek<'mem, 'facet>

Returns a readonly/immutable version of the inner type

Source

pub fn into_peek(self) -> Peek<'mem, 'facet>

Source

pub fn shape(&self) -> &'static Shape

Returns the Shape of the underlying type

The Shape is the same for Mut and Not

Source§

impl<'mem, 'facet> MaybeMut<'mem, 'facet>

Source

pub fn write<'lock>( self, ) -> Result<Guard<'lock, 'facet>, MakeLockError<'mem, 'facet>>
where 'mem: 'lock,

Try to turn MaybeMut::Not into MaybeMut::Mut

The returned MaybeMut may contain a different Shape. Which exact Shape it is, depends on what the input type was.

One edge case is if you pass a &mut Arc<RwLock<String> the type will not be changed to &mut String. But if you pass a &Arc<RwLock<String> due to locking etc, it will be a &mut String.

If the underlying type is something that can be write locked, for example an RwLock or Mutex, this method creates a lock on it.

If we already have MaybeMut::Mut this is a no-op.

If we have MaybeMut::Not and the Shape of T does not contain a PointerDef which has a vtable with a write_fn we can call with &T, this method returns Err(MaybeMut::Not). In this case, besides the lookup, it is also a no-op.

§Note

It is very important that you drop the Guard as soon as possible to free the lock

Source

pub fn read<'lock>( self, ) -> Result<Guard<'lock, 'facet>, MakeLockError<'mem, 'facet>>
where 'mem: 'lock,

Returns a Guard with a lock that is sufficent for reading.

In case of RwLock it is locked to read. If it is a Mutex, it must be exclusively locked to write but we only consider it being read which is safe

Trait Implementations§

Source§

impl<'mem, 'facet> From<Peek<'mem, 'facet>> for MaybeMut<'mem, 'facet>

Source§

fn from(value: Peek<'mem, 'facet>) -> MaybeMut<'mem, 'facet>

Converts to this type from the input type.
Source§

impl<'mem, 'facet> From<Poke<'mem, 'facet>> for MaybeMut<'mem, 'facet>

Source§

fn from(value: Poke<'mem, 'facet>) -> MaybeMut<'mem, 'facet>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'mem, 'facet> Freeze for MaybeMut<'mem, 'facet>

§

impl<'mem, 'facet> RefUnwindSafe for MaybeMut<'mem, 'facet>

§

impl<'mem, 'facet> !Send for MaybeMut<'mem, 'facet>

§

impl<'mem, 'facet> !Sync for MaybeMut<'mem, 'facet>

§

impl<'mem, 'facet> Unpin for MaybeMut<'mem, 'facet>

§

impl<'mem, 'facet> UnsafeUnpin for MaybeMut<'mem, 'facet>

§

impl<'mem, 'facet> !UnwindSafe for MaybeMut<'mem, 'facet>

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.