#[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§
Implementations§
Source§impl<'mem, 'facet> MaybeMut<'mem, 'facet>
impl<'mem, 'facet> MaybeMut<'mem, 'facet>
Sourcepub fn write<'lock>(
self,
) -> Result<Guard<'lock, 'facet>, MakeLockError<'mem, 'facet>>where
'mem: 'lock,
'facet: 'lock,
pub fn write<'lock>(
self,
) -> Result<Guard<'lock, 'facet>, MakeLockError<'mem, 'facet>>where
'mem: 'lock,
'facet: '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
Sourcepub fn read<'lock>(
self,
) -> Result<Guard<'lock, 'facet>, MakeLockError<'mem, 'facet>>where
'mem: 'lock,
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§
Auto Trait Implementations§
impl<'mem, 'facet> !Send for MaybeMut<'mem, 'facet>
impl<'mem, 'facet> !Sync for MaybeMut<'mem, 'facet>
impl<'mem, 'facet> !UnwindSafe for MaybeMut<'mem, 'facet>
impl<'mem, 'facet> Freeze for MaybeMut<'mem, 'facet>
impl<'mem, 'facet> RefUnwindSafe for MaybeMut<'mem, 'facet>
impl<'mem, 'facet> Unpin for MaybeMut<'mem, 'facet>
impl<'mem, 'facet> UnsafeUnpin for MaybeMut<'mem, 'facet>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more