Live

Struct Live 

Source
pub struct Live<T> { /* private fields */ }
Expand description

A typed view of one projection of the current configuration.

A never-dynamic consumer can hold a plain T; a dynamic one holds Live<T> and never learns whether it is fixed or tracking the live config. Read the view’s cached snapshot with Deref; wait for and receive the next selected update with changed.

For a dynamic view, Deref does not perform a fresh read from the shared configuration. It returns the last snapshot processed by this view. If the configuration advances before this view awaits changed, Deref continues to return the older snapshot until changed processes the notification.

Implementations§

Source§

impl<T: Clone + PartialEq + 'static> Live<T>

Source

pub fn new_dynamic( cell: Arc<ArcSwap<SalukiConfiguration>>, tick: Receiver<()>, project: impl for<'a> Fn(&'a SalukiConfiguration) -> &'a T + Send + Sync + 'static, ) -> Self

Creates a view that re-projects the shared configuration after accepted updates.

The projection selects the subtree this view owns. The initial projected value is captured immediately; later calls to changed load and project the shared configuration, then update this view’s local snapshot. Until changed processes a notification, Deref continues to return the previous snapshot even if the shared configuration has advanced.

Source

pub fn new_fixed(value: T) -> Self

Creates a view with a value that never changes.

Source

pub async fn changed(&mut self) -> T

Waits for the projected value to change and returns the new value.

The notification only says that the shared source may have changed. This method loads the source, applies the projection, compares it with this view’s snapshot, and keeps waiting if the selected value is unchanged. It parks forever when Fixed or the channel is closed, so a caller can select! on it unconditionally. The returned value and Deref reflect the same processed snapshot. This is a state-change watcher, not a fresh-read API or an event history: multiple source updates may be coalesced before this view processes them.

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 composing this view’s projection with f.

Use this when code already has a broad Live<T> but does not have the ConfigurationSystem needed to create a narrower view directly. A dynamic child shares the source and receives its own notification cursor and snapshot; it wakes only when the selected child value changes. A fixed child is projected 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> !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, 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> 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 = 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.