pub struct State<T: Clone + 'static> { /* private fields */ }Expand description
Cheap copyable read-only view of a state cell.
Implementations§
Source§impl<T: Clone + 'static> State<T>
impl<T: Clone + 'static> State<T>
pub fn is_alive(&self) -> bool
pub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
pub fn try_value(&self) -> Option<T>
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn value(&self) -> T
pub fn get(&self) -> T
pub fn has_subscribers(&self) -> bool
pub fn on_subscriber(&self, callback: Rc<dyn Fn()>)
Sourcepub fn subscription_hold(&self) -> StateSubscriptionHold
pub fn subscription_hold(&self) -> StateSubscriptionHold
Counts this state as subscribed for as long as the returned guard lives, without observing it from any scope.
Snapshot observers subscribe reads made under composition or the
draw phase, and producers gated on State::has_subscribers — an
infinite transition, for one — stop themselves when the last such
subscriber leaves. A consumer that reads the value from a polling
context (a frame effect stepping it into a derived state, a
background task) is invisible to that accounting and would starve
the producer it depends on. Holding this guard keeps the producer
alive; dropping it releases the count.
Trait Implementations§
impl<T: Clone + 'static> Copy for State<T>
impl<T: Clone + 'static> Eq for State<T>
Auto Trait Implementations§
impl<T> Freeze for State<T>
impl<T> RefUnwindSafe for State<T>
impl<T> Send for State<T>
impl<T> Sync for State<T>
impl<T> Unpin for State<T>
impl<T> UnsafeUnpin for State<T>
impl<T> UnwindSafe for State<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
Mutably borrows from an owned value. Read more