Trait ConsolidateLayout

Source
pub trait ConsolidateLayout: Container {
    type Key<'a>: Eq
       where Self: 'a;
    type Diff<'a>;
    type DiffOwned: for<'a> Semigroup<Self::Diff<'a>>;

    // Required methods
    fn owned_diff(diff: Self::Diff<'_>) -> Self::DiffOwned;
    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§

Source

type Key<'a>: Eq where Self: 'a

Key portion of data, essentially everything minus the diff

Source

type Diff<'a>

GAT diff type.

Source

type DiffOwned: for<'a> Semigroup<Self::Diff<'a>>

Owned diff type.

Required Methods§

Source

fn owned_diff(diff: Self::Diff<'_>) -> Self::DiffOwned

Converts a reference diff into an owned diff.

Source

fn into_parts(item: Self::Item<'_>) -> (Self::Key<'_>, Self::Diff<'_>)

Deconstruct an item into key and diff. Must be cheap.

Source

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.

Source

fn cmp(item1: &Self::Item<'_>, item2: &Self::Item<'_>) -> Ordering

Compare two items by key to sort containers.

Provided Methods§

Source

fn consolidate_into(&mut self, target: &mut Self)

Consolidate the supplied container.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<D, T, R> ConsolidateLayout for Vec<(D, T, R)>
where D: Ord + Clone + 'static, T: Ord + Clone + 'static, R: Semigroup + Clone + 'static,

Source§

fn consolidate_into(&mut self, target: &mut Self)

Consolidate the supplied container.

Source§

type Key<'a> = (D, T) where Self: 'a

Source§

type Diff<'a> = R where Self: 'a

Source§

type DiffOwned = R

Source§

fn owned_diff(diff: Self::Diff<'_>) -> Self::DiffOwned

Source§

fn into_parts( (data, time, diff): Self::Item<'_>, ) -> (Self::Key<'_>, Self::Diff<'_>)

Source§

fn cmp<'a>(item1: &Self::Item<'_>, item2: &Self::Item<'_>) -> Ordering

Source§

fn push_with_diff(&mut self, (data, time): Self::Key<'_>, diff: Self::DiffOwned)

Implementors§