pub struct Live<T> { /* private fields */ }Expand description
A typed view of one projection of a shared value.
Consumers use the same API for fixed values and for dynamic views created by LiveSource::live. Deref returns
this view’s cached snapshot, not a fresh source read. Only changed refreshes the snapshot; source
updates alone do not.
Cloning copies the snapshot and the record of which notifications this view has processed. Each view then processes updates independently.
Implementations§
Source§impl<T: Clone + PartialEq + 'static> Live<T>
impl<T: Clone + PartialEq + 'static> Live<T>
Sourcepub fn is_fixed(&self) -> bool
pub fn is_fixed(&self) -> bool
Returns true if this view’s value never changes.
A fixed view never yields from changed, so callers can treat its current value as a constant.
Sourcepub async fn changed(&mut self) -> T
pub async fn changed(&mut self) -> T
Waits until the selected value differs from this view’s snapshot, then updates the snapshot and returns it.
Notifications trigger a source read; equal values leave the call pending. The returned value matches the snapshot
exposed by Deref. Several publications can produce one observed change, skipping intermediate values.
Fixed views stay pending forever. When the publisher drops, dynamic views process any unseen notification, then
stay pending forever. Callers can therefore use select! without handling closure.
Sourcepub fn into_stream(self) -> impl Stream<Item = T> + Send + 'staticwhere
T: Send,
pub fn into_stream(self) -> impl Stream<Item = T> + Send + 'staticwhere
T: Send,
Converts this view into a stream of its changes.
Each item comes from changed: the stream skips the current snapshot but can yield a change
pending before conversion. Intermediate values may be skipped. The stream never ends, even for fixed views or
after the publisher drops.
Sourcepub fn project<U>(
&self,
f: impl for<'a> Fn(&'a T) -> &'a U + Send + Sync + 'static,
) -> Live<U>
pub fn project<U>( &self, f: impl for<'a> Fn(&'a T) -> &'a U + Send + Sync + 'static, ) -> Live<U>
Creates a child view by selecting part of this view’s value with f.
A dynamic child shares the source, but has its own snapshot and processes notifications independently. Its initial snapshot reads the source, not this view’s snapshot, so it may be newer. The child can outlive its parent. A fixed child is projected once and remains fixed.
Sourcepub fn map<U>(&self, f: impl Fn(&T) -> U + Send + Sync + 'static) -> Live<U>
pub fn map<U>(&self, f: impl Fn(&T) -> U + Send + Sync + 'static) -> Live<U>
Creates a child view by computing an owned value with f.
Unlike project, f returns an owned value rather than a reference. A dynamic child reads the
source, not this view’s cached snapshot, and processes updates independently. It calls f when created and
whenever it or its children read the source. changed compares mapped values and stays pending
when they are equal. A fixed child is mapped once and remains fixed.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Live<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Live<T>
impl<T> Send for Live<T>where
T: Send,
impl<T> Sync for Live<T>where
T: Sync,
impl<T> Unpin for Live<T>where
T: Unpin,
impl<T> UnsafeUnpin for Live<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for Live<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,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
Tracked wrapper. Read more