#[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,
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
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