pub struct Constant<T>(/* private fields */);Expand description
A reactive constant value that never changes.
Constant<T> is a simple implementation of the Signal trait that always
returns the same value when computed. It serves as a way to introduce static
values into a reactive computation graph.
§Type Parameters
T: The value type, which must beClone + 'static.
§Examples
use nami::{Signal, constant};
let c = constant(42);
assert_eq!(c.get(), 42);Trait Implementations§
Source§impl<T> Signal for Constant<T>where
T: Clone + 'static,
impl<T> Signal for Constant<T>where
T: Clone + 'static,
Source§fn get(&self) -> <Constant<T> as Signal>::Output
fn get(&self) -> <Constant<T> as Signal>::Output
Computes the constant value.
This simply returns a clone of the contained value.
§Returns
A clone of the constant value.
Source§fn watch(&self, _watcher: impl Fn(Context<<Constant<T> as Signal>::Output>))
fn watch(&self, _watcher: impl Fn(Context<<Constant<T> as Signal>::Output>))
Adds a watcher to this constant.
Since a constant never changes, this function returns a WatcherGuard
with an empty cleanup function. The provided watcher will never be notified
of any changes.
§Parameters
_watcher: A watcher that would be notified of changes (unused).
§Returns
A WatcherGuard with an empty cleanup function.
Auto Trait Implementations§
impl<T> Freeze for Constant<T>where
T: Freeze,
impl<T> RefUnwindSafe for Constant<T>where
T: RefUnwindSafe,
impl<T> Send for Constant<T>where
T: Send,
impl<T> Sync for Constant<T>where
T: Sync,
impl<T> Unpin for Constant<T>where
T: Unpin,
impl<T> UnwindSafe for Constant<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<S> AnimationExt for Swhere
S: SignalExt,
impl<S> AnimationExt for Swhere
S: SignalExt,
Source§fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
Apply default animation to this reactive value Read more
Source§fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
Apply a specific animation to this reactive value Read more
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<C, F, T1, T2, Output> FlattenMap<F, (T1, T2), Output> for C
impl<C, F, T1, T2, Output> FlattenMap<F, (T1, T2), Output> for C
Source§impl<C, F, T1, T2, T3, Output> FlattenMap<F, (T1, T2, T3), Output> for C
impl<C, F, T1, T2, T3, Output> FlattenMap<F, (T1, T2, T3), Output> for C
Source§impl<T> IdentifiableExt for T
impl<T> IdentifiableExt for T
Source§impl<C> SignalExt for Cwhere
C: Signal,
impl<C> SignalExt for Cwhere
C: Signal,
Source§fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
Transforms the output of this signal using the provided function.
Source§fn cached(self) -> Cached<Self>
fn cached(self) -> Cached<Self>
Wraps this signal with caching to avoid redundant computations.
Source§fn computed(self) -> Computed<Self::Output>where
Self: 'static,
fn computed(self) -> Computed<Self::Output>where
Self: 'static,
Converts this signal into a type-erased
Computed container.Source§fn with<T>(self, metadata: T) -> WithMetadata<Self, T>
fn with<T>(self, metadata: T) -> WithMetadata<Self, T>
Attaches metadata to this signal’s watcher notifications.