pub struct Shared<T: 'static, B: 'static> {
pub id: Option<usize>,
/* private fields */
}Expand description
A hook to a shared_value.
This is generally created by calling use_rw or use_w on a shareable!, or by
calling ListEntry::use_rw or
ListEntry::use_w.
Fields§
§id: Option<usize>Implementations§
Sourcepub fn init<'a, P, F: FnOnce() -> T>(
cx: &Scope<'a, P>,
opt: &mut Shareable<T>,
f: F,
_: B,
) -> &'a mut Self
pub fn init<'a, P, F: FnOnce() -> T>( cx: &Scope<'a, P>, opt: &mut Shareable<T>, f: F, _: B, ) -> &'a mut Self
Initialize the hook in scope cx.
The shared value will be initialized with f() if it hasn’t been created yet.
NOTE: this method should generally not be used directly; instead, shared values are usually
created with shareable!.
Sourcepub fn write(&self) -> MappedRwLockWriteGuard<'_, T>
pub fn write(&self) -> MappedRwLockWriteGuard<'_, T>
Obtain a write pointer to the shared value and register the change.
This will mark all components which hold a RW link to the value as needing update.
Sourcepub fn write_silent(&self) -> MappedRwLockWriteGuard<'_, T>
pub fn write_silent(&self) -> MappedRwLockWriteGuard<'_, T>
Obtain a write pointer to the shared value but do not register the change.
This will not notify consumers of the change to the value.
Sourcepub fn needs_update(&self)
pub fn needs_update(&self)
Mark the components which hold a RW link to the value as needing update.
Sourcepub fn set(&self, t: T)where
T: PartialEq,
pub fn set(&self, t: T)where
T: PartialEq,
Set the shared value.
This marks compoments which hold a RW link to the value as needing update if and only if the value has changed.
Sourcepub fn set_with<F: Fn(&T) -> T>(&self, f: F)where
T: PartialEq,
pub fn set_with<F: Fn(&T) -> T>(&self, f: F)where
T: PartialEq,
Set the shared value to f(&x) where x is the current value.
This marks components which hold a RW link to the value as needing update if and only if the value has changed.
Sourcepub fn read(&self) -> MappedRwLockReadGuard<'_, T>
pub fn read(&self) -> MappedRwLockReadGuard<'_, T>
Get the value of the shared data.