pub struct VarWriteGuard<'a, T>{ /* private fields */ }Expand description
A write lock guard returned by Var::write or WeakVar::write.
While the guard is alive, it holds an exclusive lock on the underlying value. When the guard is dropped, the variable is registered as having been read and, by default, written, which bumps the variable’s version and triggers dependent UI updates.
If no observable change occurred, call VarWriteGuard::cancel_change
before dropping the guard to prevent the version bump.
Mapped guards produced by VarWriteGuard::map and friends preserve the same
behavior: the write is committed (unless canceled) when the final mapped guard
is dropped.
Implementations§
Source§impl<'a, T> VarWriteGuard<'a, T>
impl<'a, T> VarWriteGuard<'a, T>
Sourcepub fn cancel_change(&mut self)
pub fn cancel_change(&mut self)
Prevents the dependency tracking system from registering a change.
When this is called, the Var’s version number will not be incremented upon Drop.
Sourcepub fn map<U>(
this: VarWriteGuard<'a, T>,
f: impl FnOnce(&mut T) -> &mut U,
) -> VarWriteGuard<'a, U>
pub fn map<U>( this: VarWriteGuard<'a, T>, f: impl FnOnce(&mut T) -> &mut U, ) -> VarWriteGuard<'a, U>
Maps a write guard to a subfield, like RwLockWriteGuard::map.
This is an associated function that needs to be used as VarWriteGuard::map(...).
Sourcepub fn try_map<U>(
this: VarWriteGuard<'a, T>,
f: impl FnOnce(&mut T) -> Option<&mut U>,
) -> Result<VarWriteGuard<'a, U>, VarWriteGuard<'a, T>>
pub fn try_map<U>( this: VarWriteGuard<'a, T>, f: impl FnOnce(&mut T) -> Option<&mut U>, ) -> Result<VarWriteGuard<'a, U>, VarWriteGuard<'a, T>>
Fallible map, like RwLockWriteGuard::try_map.
This is an associated function that needs to be used as VarWriteGuard::try_map(...).
Sourcepub fn try_map_or_err<U, E>(
this: VarWriteGuard<'a, T>,
f: impl FnOnce(&mut T) -> Result<&mut U, E>,
) -> Result<VarWriteGuard<'a, U>, (VarWriteGuard<'a, T>, E)>
pub fn try_map_or_err<U, E>( this: VarWriteGuard<'a, T>, f: impl FnOnce(&mut T) -> Result<&mut U, E>, ) -> Result<VarWriteGuard<'a, U>, (VarWriteGuard<'a, T>, E)>
Fallible map, like RwLockWriteGuard::try_map, but returns the error produced by the mapping function.
This is an associated function that needs to be used as VarWriteGuard::try_map_or_err(...).