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: SnapshotInitial snapshot of the data
updates: UpdatesStream 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>)>,
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>)>,
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>)>,
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>
impl<Snapshot, Updates> SnapshotWithUpdates<Snapshot, Updates>
Sourcepub fn into_inner(self) -> (Snapshot, Updates)
pub fn into_inner(self) -> (Snapshot, Updates)
Converts the struct into a tuple of (snapshot, updates)
Sourcepub async fn from_stream(stream: Updates) -> Option<Self>
pub async fn from_stream(stream: Updates) -> Option<Self>
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.
Sourcepub fn into_stream(
self,
) -> impl Stream<Item = SnapshotOrUpdate<Snapshot, Updates::Item>>where
Updates: Stream,
pub fn into_stream(
self,
) -> impl Stream<Item = SnapshotOrUpdate<Snapshot, Updates::Item>>where
Updates: Stream,
Converts SnapshotWithUpdates into a Stream of SnapshotOrUpdate
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>)>,
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>)>,
Sourcepub fn into_snapshots(
self,
) -> SnapshotWithUpdates<HashMap<Key, Value>, impl Stream<Item = HashMap<Key, Value>>>
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.
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>)>>>
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>)>>>
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>)>>>
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§
Auto Trait Implementations§
impl<Snapshot, Updates> Freeze for SnapshotWithUpdates<Snapshot, Updates>
impl<Snapshot, Updates> RefUnwindSafe for SnapshotWithUpdates<Snapshot, Updates>where
Snapshot: RefUnwindSafe,
Updates: RefUnwindSafe,
impl<Snapshot, Updates> Send for SnapshotWithUpdates<Snapshot, Updates>
impl<Snapshot, Updates> Sync for SnapshotWithUpdates<Snapshot, Updates>
impl<Snapshot, Updates> Unpin for SnapshotWithUpdates<Snapshot, Updates>
impl<Snapshot, Updates> UnwindSafe for SnapshotWithUpdates<Snapshot, Updates>where
Snapshot: UnwindSafe,
Updates: UnwindSafe,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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