Struct SnapshotWithUpdates

Source
pub struct SnapshotWithUpdates<Snapshot, Updates> {
    pub snapshot: Snapshot,
    pub updates: Updates,
}
Expand description

Wraps a ‘snapshot’ (initial data) with updates (some kind of update which can be applied to the snapshot to update).

This is useful for modelling behaviour of CRUD repositories where updates are also monitored.

Fields§

§snapshot: Snapshot

Initial snapshot of the data

§updates: Updates

Stream of updates that can be applied to the snapshot

Implementations§

Source§

impl<Key, Value, Snapshot, Updates> SnapshotWithUpdates<Snapshot, Updates>
where Key: Clone + Hash + Eq, Value: Clone, Snapshot: IntoIterator<Item = (Key, Value)>, Updates: Stream, Updates::Item: IntoIterator<Item = (Key, Option<Value>)>,

Source

pub fn join_with_optional_parent<ParentKey, ParentValue, ParentSnapshot, ParentUpdates>( self, other: SnapshotWithUpdates<ParentSnapshot, ParentUpdates>, f: impl FnMut(&Key) -> ParentKey, ) -> SnapshotWithUpdates<impl IntoIterator<Item = ((ParentKey, Key), (Option<ParentValue>, Value))>, impl Stream<Item = impl IntoIterator<Item = ((ParentKey, Key), Option<(Option<ParentValue>, Value)>)>>>
where ParentKey: Clone + Hash + Eq, Snapshot::Item: Clone, ParentSnapshot: IntoIterator<Item = (ParentKey, ParentValue)>, ParentValue: Clone, ParentUpdates: Stream, ParentUpdates::Item: IntoIterator<Item = (ParentKey, Option<ParentValue>)>,

Source

pub fn join_with_parent<ParentKey, ParentValue, ParentSnapshot, ParentUpdates>( self, other: SnapshotWithUpdates<ParentSnapshot, ParentUpdates>, f: impl FnMut(&Key) -> ParentKey, ) -> SnapshotWithUpdates<impl IntoIterator<Item = ((ParentKey, Key), (ParentValue, Value))>, impl Stream<Item = impl IntoIterator<Item = ((ParentKey, Key), Option<(ParentValue, Value)>)>>>
where ParentKey: Clone + Hash + Eq, Snapshot::Item: Clone, ParentSnapshot: IntoIterator<Item = (ParentKey, ParentValue)>, ParentValue: Clone, ParentUpdates: Stream, ParentUpdates::Item: IntoIterator<Item = (ParentKey, Option<ParentValue>)>,

Source§

impl<Snapshot, Updates> SnapshotWithUpdates<Snapshot, Updates>

Source

pub fn new(snapshot: Snapshot, updates: Updates) -> Self

Constructor

Source

pub fn into_inner(self) -> (Snapshot, Updates)

Converts the struct into a tuple of (snapshot, updates)

Source

pub async fn from_stream(stream: Updates) -> Option<Self>
where Updates: Stream<Item = Snapshot> + Unpin,

Creates SnapshotWithUpdates by taking the first item of the stream as the ‘snapshot’ and subsequent items as ‘updates’. Returns None if the stream doesn’t contain any items.

Source

pub fn into_stream( self, ) -> impl Stream<Item = SnapshotOrUpdate<Snapshot, Updates::Item>>
where Updates: Stream,

Source

pub fn flatten(self) -> impl Stream<Item = Snapshot>
where Updates: Stream<Item = Snapshot>,

Converts SnapshotWithUpdates into a Stream snapshots when Updates::Item is Snapshot

Source§

impl<Key, Value, Snapshot, Updates> SnapshotWithUpdates<Snapshot, Updates>
where Key: Clone + Hash + Eq, Value: Clone, Snapshot: IntoIterator<Item = (Key, Value)>, Updates: Stream, Updates::Item: IntoIterator<Item = (Key, Option<Value>)>,

Source

pub fn into_snapshots( self, ) -> SnapshotWithUpdates<HashMap<Key, Value>, impl Stream<Item = HashMap<Key, Value>>>

Aggregates updates into a stream of snapshots by sequentially applying updates to the initial snapshot.

Source

pub fn map_keys<R>( self, f: impl Fn(Key) -> R + Clone, ) -> SnapshotWithUpdates<impl IntoIterator<Item = (R, Value)>, impl Stream<Item = impl IntoIterator<Item = (R, Option<Value>)>>>

Source

pub fn map_values<R>( self, f: impl Fn(Value) -> R + Clone, ) -> SnapshotWithUpdates<impl IntoIterator<Item = (Key, R)>, impl Stream<Item = impl IntoIterator<Item = (Key, Option<R>)>>>

Source

pub fn filter( self, f: impl Fn(&Key, &Value) -> bool + Clone, ) -> SnapshotWithUpdates<impl IntoIterator<Item = (Key, Value)>, impl Stream<Item = impl IntoIterator<Item = (Key, Option<Value>)>>>

Source

pub fn filter_keys( self, f: impl Fn(&Key) -> bool + Clone, ) -> SnapshotWithUpdates<impl IntoIterator<Item = (Key, Value)>, impl Stream<Item = impl IntoIterator<Item = (Key, Option<Value>)>>>

Trait Implementations§

Source§

impl<Snapshot: Debug, Updates: Debug> Debug for SnapshotWithUpdates<Snapshot, Updates>

Source§

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

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

impl<T: Clone + Send + Sync + 'static> From<Receiver<T>> for SnapshotWithUpdates<T, Skip<WatchStream<T>>>

Available on crate feature tokio-sync only.
Source§

fn from(rx: Receiver<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Snapshot, Updates> Freeze for SnapshotWithUpdates<Snapshot, Updates>
where Snapshot: Freeze, Updates: Freeze,

§

impl<Snapshot, Updates> RefUnwindSafe for SnapshotWithUpdates<Snapshot, Updates>
where Snapshot: RefUnwindSafe, Updates: RefUnwindSafe,

§

impl<Snapshot, Updates> Send for SnapshotWithUpdates<Snapshot, Updates>
where Snapshot: Send, Updates: Send,

§

impl<Snapshot, Updates> Sync for SnapshotWithUpdates<Snapshot, Updates>
where Snapshot: Sync, Updates: Sync,

§

impl<Snapshot, Updates> Unpin for SnapshotWithUpdates<Snapshot, Updates>
where Snapshot: Unpin, Updates: Unpin,

§

impl<Snapshot, Updates> UnwindSafe for SnapshotWithUpdates<Snapshot, Updates>
where Snapshot: UnwindSafe, Updates: UnwindSafe,

Blanket Implementations§

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> 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.