pub struct Signal<T: 'static>(/* private fields */);Implementations§
Source§impl<T> Signal<T>
impl<T> Signal<T>
pub fn new(value: T) -> Self
pub fn id(&self) -> usize
pub fn get(&self) -> Twhere
T: Clone,
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Read the current value without cloning it, tracking the read in the
reactive graph. Prefer over get for large/expensive-to-clone types.
Sourcepub fn set_neq(&self, v: T)
pub fn set_neq(&self, v: T)
Set the signal value only if it changed, skipping subscribers, the reactive graph, and the frame request when the value is unchanged.
Sourcepub fn set(&self, v: T)where
T: Clone,
pub fn set(&self, v: T)where
T: Clone,
Set the signal value and notify subscribers + the reactive graph.
Always notifies, even if the value is equal - prefer set_neq for UI
state where equality is cheap.
Subscribers observe a snapshot clone, so re-entrant set/update
inside a subscriber cannot alias the reference they hold.
pub fn update<F: FnOnce(&mut T)>(&self, f: F)where
T: Clone,
pub fn subscribe(&self, f: impl Fn(&T) + 'static) -> SubId
Sourcepub fn unsubscribe(&self, id: SubId) -> bool
pub fn unsubscribe(&self, id: SubId) -> bool
Remove a subscriber by id. Returns true if removed.
Sourcepub fn subscribe_guard(&self, f: impl Fn(&T) + 'static) -> SubGuard<T>
pub fn subscribe_guard(&self, f: impl Fn(&T) + 'static) -> SubGuard<T>
Subscribe and get a guard that auto-unsubscribes on drop.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Signal<T>
impl<T> !Send for Signal<T>
impl<T> !Sync for Signal<T>
impl<T> !UnwindSafe for Signal<T>
impl<T> Freeze for Signal<T>
impl<T> Unpin for Signal<T>
impl<T> UnsafeUnpin for Signal<T>
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
Mutably borrows from an owned value. Read more