Skip to main content

LocalState

Struct LocalState 

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

Scoped reactive local component state automatically disposed on unmount and frozen/resumed with its owning Scope.

Implementations§

Source§

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

Scoped local state creation, reading, writing, and change observation for LocalState<T>.

Source

pub fn new(initial: T) -> Self

Creates a new reactive LocalState<T> owned by the active component or page Scope.

§Arguments
  • T - Initial local state value.
§Returns
  • Self - Lightweight handle to the local reactive state.
Source

pub fn signal(&self) -> Signal<T>

Returns the underlying Signal<T> handle for interoperability with view! and widgets.

§Arguments
  • &Self - Local state handle.
§Returns
  • Signal<T> - Underlying fine-grained reactive signal.
Source

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

Reads the current value reactively and registers dependency tracking on the active observer.

§Arguments
  • &Self - Local state handle.
§Returns
  • T - Current cloned state value.
Source

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

Reads the current value without tracking dependencies.

§Arguments
  • &Self - Local state handle.
§Returns
  • T - Current cloned state value.
Source

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

Replaces the stored local state value and notifies active subscribers.

§Arguments
  • &Self - Local state handle.
  • T - Replacement value.
§Returns
  • bool - true when the state slot is still alive.
Source

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

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

§Arguments
  • &Self - Local state handle.
  • T - Candidate replacement value.
§Returns
  • bool - true when the value changed and subscribers were notified.
Source

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

Mutates the stored local state in place via updater.

§Arguments
  • &Self - Local state handle.
  • F - In-place mutation closure.
§Returns
  • bool - true when updated.
Source

pub fn watch<F>(&self, handler: F) -> Effect
where T: Clone, F: FnMut(&T, &T) + 'static,

Subscribes a change watcher receiving (&previous, &next) whenever this local state mutates.

§Arguments
  • &Self - Local state handle.
  • F - Change observer invoked on subsequent mutations (skipped during Scope::freeze(), coalesced on Scope::resume()).
§Returns
  • Effect - Scope-owned watcher effect handle.

Trait Implementations§

Source§

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

Clone handle semantics for LocalState<T>.

Source§

fn clone(&self) -> Self

Copies the lightweight LocalState<T> handle.

§Arguments
  • &Self - Source handle.
§Returns
  • Self - Copied handle pointing to the same local state slot.
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 LocalState<T>
where T: 'static,

Copy handle semantics for LocalState<T>.

Source§

impl<T> Debug for LocalState<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 LocalState<T>
where T: 'static,

Full equality marker for LocalState<T>.

Source§

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

Handle equality comparison for LocalState<T>.

Source§

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

Compares two LocalState<T> handles by underlying signal identity.

§Arguments
  • &Self - Left handle.
  • &Self - Right handle.
§Returns
  • bool - true when both handles reference the same state slot.
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> Forget for LocalState<T>

§

impl<T> Freeze for LocalState<T>
where Signal<T>: Freeze,

§

impl<T> Move for LocalState<T>

§

impl<T> RefUnwindSafe for LocalState<T>

§

impl<T> Send for LocalState<T>
where Signal<T>: Send,

§

impl<T> Sync for LocalState<T>
where Signal<T>: Sync,

§

impl<T> Unpin for LocalState<T>
where Signal<T>: Unpin,

§

impl<T> UnsafeUnpin for LocalState<T>
where Signal<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for LocalState<T>
where Signal<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.