pub struct Signal<T>{ /* private fields */ }Expand description
A reactive signal handle.
Allows reading, writing, and subscribing to changes.
Implements Clone and Copy for ergonomic use; all copies share the same
underlying state. The inner state is heap-allocated via Rc<RefCell<>> and
tracked in a global registry to prevent premature deallocation. The Copy
semantics are safe because only the pointer address is copied — the actual
Rc reference is held by the registry for the lifetime of the program.
Implementations§
Source§impl<T> Signal<T>
Implementation of reactive signal operations.
impl<T> Signal<T>
Implementation of reactive signal operations.
Sourcepub fn try_get(&self) -> Option<T>
pub fn try_get(&self) -> Option<T>
Attempts to return the current value of the signal without panicking.
§Returns
Some(T)- The current value if the borrow succeeds.None- If the inner value is already mutably borrowed.
Sourcepub fn subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
pub fn subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
Subscribes a callback to be invoked when the signal changes.
§Arguments
FnMut() + 'static- The callback to invoke when the signal changes.
Sourcepub fn replace_subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
pub fn replace_subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
Replaces all listeners with a single new callback.
Unlike subscribe, which appends a listener, this method clears any
existing listeners first and then adds the new one.
§Arguments
FnMut() + 'static- The callback to invoke when the signal changes.
Sourcepub fn clear_listeners(&self)
pub fn clear_listeners(&self)
Removes all subscribed listeners from this signal and marks it as inactive.
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Sets the value of the signal and notifies listeners.
§Arguments
T- The new value to assign to the signal.
Sourcepub fn set_silent(&self, value: T)
pub fn set_silent(&self, value: T)
Sets the value of the signal and notifies listeners without scheduling a global DOM update dispatch.
§Arguments
T- The new value to assign to the signal.
Source§impl<T> Signal<T>
impl<T> Signal<T>
pub fn get_mut_inner(&mut self) -> &mut usize
pub fn get_mut__marker(&mut self) -> &mut PhantomData<fn() -> T>
Trait Implementations§
Source§impl<T> Deref for Signal<T>
Prevents direct dereference of a signal to enforce explicit API usage.
impl<T> Deref for Signal<T>
Prevents direct dereference of a signal to enforce explicit API usage.
Source§impl<T> DerefMut for Signal<T>
Prevents direct mutable dereference of a signal to enforce explicit API usage.
impl<T> DerefMut for Signal<T>
Prevents direct mutable dereference of a signal to enforce explicit API usage.
Source§impl<T> IntoNode for Signal<T>
Converts a signal into a reactive text virtual node via IntoNode.
impl<T> IntoNode for Signal<T>
Converts a signal into a reactive text virtual node via IntoNode.
Source§fn into_node(self) -> VirtualNode
fn into_node(self) -> VirtualNode
Converts this signal into a reactive text virtual node.
§Returns
VirtualNode- A reactive text virtual node.
Source§impl IntoReactiveString for Signal<String>
Converts a string signal into a reactive string by resolving its current value.
impl IntoReactiveString for Signal<String>
Converts a string signal into a reactive string by resolving its current value.
Source§fn into_reactive_string(self) -> String
fn into_reactive_string(self) -> String
Source§impl IntoReactiveString for Signal<bool>
Converts a bool signal into a reactive string by resolving its current value.
impl IntoReactiveString for Signal<bool>
Converts a bool signal into a reactive string by resolving its current value.
Source§fn into_reactive_string(self) -> String
fn into_reactive_string(self) -> String
Resolves the current value of this bool signal as a string.
§Returns
String- The current boolean value as"true"or"false".
Source§impl IntoReactiveValue for Signal<String>
Converts a string signal into a reactive attribute value.
impl IntoReactiveValue for Signal<String>
Converts a string signal into a reactive attribute value.
Source§fn into_reactive_value(self) -> AttributeValue
fn into_reactive_value(self) -> AttributeValue
Converts this string signal into an AttributeValue::Signal.
§Returns
AttributeValue- A signal-backed attribute value.
Source§impl IntoReactiveValue for Signal<bool>
Converts a mutable bool signal into a reactive attribute value.
impl IntoReactiveValue for Signal<bool>
Converts a mutable bool signal into a reactive attribute value.
The signal is mapped to a Signal<String> that yields "true" or "false",
enabling boolean attributes like checked to reactively update the DOM.
Source§fn into_reactive_value(self) -> AttributeValue
fn into_reactive_value(self) -> AttributeValue
Converts this bool signal into an AttributeValue via string mapping.
§Returns
AttributeValue- A signal-backed attribute value yielding"true"or"false".
impl<T> Copy for Signal<T>
Copies the signal, sharing the same inner state.