Skip to main content

Signal

Struct Signal 

Source
pub struct Signal<T>
where T: 'static,
{ /* private fields */ }
Expand description

Zero-overhead Copy handle to a fine-grained reactive signal stored in the arena.

Implementations§

Source§

impl<T> Signal<T>
where T: 'static,

Core reactive operations for Signal<T>.

Source

pub fn new(initial_value: T) -> Self

Allocates a new reactive signal initialized with initial_value.

§Arguments
  • T - Initial signal value.
§Returns
  • Self - Copyable handle to the created signal.
Source

pub fn new_detached(initial_value: T) -> Self

Allocates a new reactive signal detached from any enclosing transient Scope so hub/store state survives UI rebuilds.

§Arguments
  • T - Initial signal value.
§Returns
  • Self - Copyable handle to the created detached signal.
Source

pub fn id(&self) -> SignalId

Returns the underlying SignalId.

§Arguments
  • &Self - Signal handle.
§Returns
  • SignalId - Underlying arena identifier.
Source

pub fn track(&self)

Records a dependency on this signal in the active observer without cloning its value.

§Arguments
  • &Self - Signal handle to track.
Source

pub fn try_get(&self) -> Option<T>
where T: Clone,

Reads the current value by cloning and tracks the active observer dependency.

§Arguments
  • &Self - Signal handle to read.
§Returns
  • Option<T> - Current value if the signal is still alive.
Source

pub fn get(&self) -> T
where T: Clone + Default,

Reads the current value, returning T::default() if the signal was disposed.

§Arguments
  • &Self - Signal handle to read.
§Returns
  • T - Current value or default fallback.
Source

pub fn try_get_untracked(&self) -> Option<T>
where T: Clone,

Reads the current value without tracking any reactive dependency.

§Arguments
  • &Self - Signal handle to inspect.
§Returns
  • Option<T> - Current value if alive.
Source

pub fn get_untracked(&self) -> T
where T: Clone + Default,

Reads the current value untracked, returning T::default() if disposed.

§Arguments
  • &Self - Signal handle to inspect.
§Returns
  • T - Current value or default fallback.
Source

pub fn with<F, R>(&self, reader: F) -> Option<R>
where T: Clone, F: FnOnce(&T) -> R,

Applies reader to a cloned snapshot outside any RefCell borrow so nested reads remain safe.

§Arguments
  • &Self - Signal handle to read.
  • F - Reader closure receiving &T.
§Returns
  • Option<R> - Closure return value if the signal is alive.
Source

pub fn set(&self, value: T) -> bool

Replaces the stored value and flushes downstream reactive effects.

§Arguments
  • &Self - Signal handle to write.
  • T - Replacement value.
§Returns
  • bool - True when the signal was alive and updated.
Source

pub fn set_if_changed(&self, value: T) -> bool
where T: PartialEq,

Replaces the stored value only when value differs from the current stored value.

§Arguments
  • &Self - Signal handle to write.
  • T - Candidate value.
§Returns
  • bool - True when the value changed and downstream effects were scheduled.
Source

pub fn update<F>(&self, updater: F) -> bool
where T: Clone, F: FnOnce(&mut T),

Mutates the signal value using updater outside the runtime borrow and flushes effects.

§Arguments
  • &Self - Signal handle to update.
  • F - Mutation closure receiving &mut T.
§Returns
  • bool - True when the signal was alive and updated.
Source

pub fn dispose(&self)

Disposes this signal and reclaims its arena slot.

§Arguments
  • &Self - Signal handle to dispose.

Trait Implementations§

Source§

impl<T> Clone for Signal<T>
where T: 'static,

Manual Clone implementation so Signal<T> is always Copy regardless of T.

Source§

fn clone(&self) -> Self

Copies the lightweight 8-byte signal handle.

§Arguments
  • &Self - Signal handle to copy.
§Returns
  • Self - Identical signal handle.
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Copy for Signal<T>
where T: 'static,

Marker Copy implementation for Signal<T>.

Source§

impl<T> Debug for Signal<T>
where T: 'static + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Eq for Signal<T>
where T: 'static,

Reflexive equality for Signal<T>.

Source§

impl<T> Hash for Signal<T>
where T: 'static,

Hash implementation based on underlying SignalId.

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Hashes the underlying arena signal identifier.

§Arguments
  • &Self - Signal handle to hash.
  • &mut H - Hasher state.
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for Signal<T>
where T: 'static,

Equality comparison by underlying SignalId.

Source§

fn eq(&self, other: &Self) -> bool

Compares two signal handles by arena identifier.

§Arguments
  • &Self - Left-hand signal handle.
  • &Self - Right-hand signal handle.
§Returns
  • bool - True if both handles reference the same arena slot and generation.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> Forget for Signal<T>

§

impl<T> Freeze for Signal<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> Move for Signal<T>

§

impl<T> RefUnwindSafe for Signal<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for Signal<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for Signal<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for Signal<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Signal<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Signal<T>
where PhantomData<fn() -> T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.