pub trait ConsolidateLayout: Container {
type Key<'a>: Eq
where Self: 'a;
type Diff<'a>: IntoOwned<'a, Owned = Self::DiffOwned>
where Self: 'a;
type DiffOwned: for<'a> Semigroup<Self::Diff<'a>>;
// Required methods
fn into_parts(item: Self::Item<'_>) -> (Self::Key<'_>, Self::Diff<'_>);
fn push_with_diff(&mut self, key: Self::Key<'_>, diff: Self::DiffOwned);
fn cmp(item1: &Self::Item<'_>, item2: &Self::Item<'_>) -> Ordering;
// Provided method
fn consolidate_into(&mut self, target: &mut Self) { ... }
}
Expand description
Layout of containers and their read items to be consolidated.
This trait specifies behavior to extract keys and diffs from container’s read items. Consolidation accumulates the diffs per key.
The trait requires Container
to have access to its Item
GAT.
Required Associated Types§
Required Methods§
sourcefn into_parts(item: Self::Item<'_>) -> (Self::Key<'_>, Self::Diff<'_>)
fn into_parts(item: Self::Item<'_>) -> (Self::Key<'_>, Self::Diff<'_>)
Deconstruct an item into key and diff. Must be cheap.
sourcefn push_with_diff(&mut self, key: Self::Key<'_>, diff: Self::DiffOwned)
fn push_with_diff(&mut self, key: Self::Key<'_>, diff: Self::DiffOwned)
Push an element to a compatible container.
This function is odd to have, so let’s explain why it exists. Ideally, the container
would accept a (key, diff)
pair and we wouldn’t need this function. However, we
might never be in a position where this is true: Vectors can push any T
, which would
collide with a specific implementation for pushing tuples of mixes GATs and owned types.
For this reason, we expose a function here that takes a GAT key and an owned diff, and
leave it to the implementation to “patch” a suitable item that can be pushed into self
.
Provided Methods§
sourcefn consolidate_into(&mut self, target: &mut Self)
fn consolidate_into(&mut self, target: &mut Self)
Consolidate the supplied container.
Object Safety§
Implementations on Foreign Types§
source§impl<D, T, R> ConsolidateLayout for Vec<(D, T, R)>
impl<D, T, R> ConsolidateLayout for Vec<(D, T, R)>
source§fn consolidate_into(&mut self, target: &mut Self)
fn consolidate_into(&mut self, target: &mut Self)
Consolidate the supplied container.