Struct LocalState
pub struct LocalState<T> { /* private fields */ }Expand description
A cloneable handle to typed, process-local application state.
Clones refer to the same value. Mutations advance an internal revision so bound widgets can skip formatting work when nothing changed.
Implementations§
§impl<T> LocalState<T>
impl<T> LocalState<T>
pub fn new(value: T) -> LocalState<T>
pub fn with<R>(&self, read: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, read: impl FnOnce(&T) -> R) -> R
Read the current value without exposing the backing lock.
pub fn set(&self, value: T)
pub fn set(&self, value: T)
Replace the value and invalidate widgets bound to this handle.
At revision exhaustion this is a no-op. Use Self::try_set when the
caller needs to observe that failure.
pub fn try_set(&self, value: T) -> bool
pub fn try_set(&self, value: T) -> bool
As Self::set, reporting whether the replacement was published.
Returns false when the captured owner is closed or the revision
namespace is exhausted. The value is then left untouched, so a bound
widget cannot mistake a new value for one it already observed under a
wrapped revision.
pub fn update(&self, update: impl FnOnce(&mut T))
pub fn update(&self, update: impl FnOnce(&mut T))
Mutate the value and invalidate widgets bound to this handle once.
At revision exhaustion this is a no-op. Use Self::try_update when
the caller needs to observe that failure.
pub fn try_update(&self, update: impl FnOnce(&mut T)) -> bool
pub fn try_update(&self, update: impl FnOnce(&mut T)) -> bool
As Self::update, reporting whether update ran. Returns false
when the captured owner is closed or at revision exhaustion, without
invoking update.
pub fn writer(&self) -> LocalStateWriter<T>
pub fn writer(&self) -> LocalStateWriter<T>
Create a thread-safe writer that wakes this state’s captured owner after mutation.
The owner is captured once by LocalState::new, so writers requested
under another app keep the original destination. State created outside
a wake scope is permanently detached. Live apps should construct state
and roots inside an App factory or explicit scope.
§impl<T> LocalState<T>where
T: Clone,
impl<T> LocalState<T>where
T: Clone,
pub fn get(&self) -> T
Trait Implementations§
§impl<T> Clone for LocalState<T>
impl<T> Clone for LocalState<T>
§fn clone(&self) -> LocalState<T>
fn clone(&self) -> LocalState<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> Freeze for LocalState<T>
impl<T> RefUnwindSafe for LocalState<T>
impl<T> Send for LocalState<T>
impl<T> Sync for LocalState<T>
impl<T> Unpin for LocalState<T>
impl<T> UnsafeUnpin for LocalState<T>
impl<T> UnwindSafe for LocalState<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more