Skip to main content

Live

Struct Live 

Source
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>

Source

pub fn new_fixed(value: T) -> Self

Creates a view with a value that never changes.

Source

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.

Source

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.

Source

pub fn into_stream(self) -> impl Stream<Item = T> + Send + 'static
where 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.

Source

pub fn project<U>( &self, f: impl for<'a> Fn(&'a T) -> &'a U + Send + Sync + 'static, ) -> Live<U>
where U: Clone + PartialEq + 'static,

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.

Source

pub fn map<U>(&self, f: impl Fn(&T) -> U + Send + Sync + 'static) -> Live<U>
where U: Clone + PartialEq + 'static,

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§

Source§

impl<T: Clone> Clone for Live<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Live<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for Live<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.

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, A, P> Access<T> for P
where A: Access<T> + ?Sized, P: Deref<Target = A>,

Source§

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more
Source§

fn load(&self) -> <P as Access<T>>::Guard

The loading method. Read more
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, A> DynAccess<T> for A
where A: Access<T>, <A as Access<T>>::Guard: 'static,

Source§

fn load(&self) -> DynGuard<T>

The equivalent of Access::load.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> Track for T

Source§

fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ

Instruments this type by attaching the given resource group token, returning a Tracked wrapper. Read more
Source§

fn in_current_resource_group(self) -> Tracked<Self> ⓘ

Instruments this type by attaching the current resource group, returning a Tracked wrapper. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Formattable for T
where T: Deref, <T as Deref>::Target: Formattable,

Source§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,