Trait timely_container::ContainerBuilder

source ·
pub trait ContainerBuilder: Default + 'static {
    type Container: Container + Clone + 'static;

    // Required methods
    fn extract(&mut self) -> Option<&mut Self::Container>;
    fn finish(&mut self) -> Option<&mut Self::Container>;

    // Provided method
    fn partition<I>(
        container: &mut Self::Container,
        builders: &mut [Self],
        index: I,
    )
       where Self: for<'a> PushInto<<Self::Container as Container>::Item<'a>>,
             Self::Container: SizableContainer,
             I: for<'a> FnMut(&<Self::Container as Container>::Item<'a>) -> usize { ... }
}
Expand description

A type that can build containers from items.

An implementation needs to absorb elements, and later reveal equivalent information chunked into individual containers, but is free to change the data representation to better fit the properties of the container.

Types implementing this trait should provide appropriate PushInto implementations such that users can push the expected item types.

The owner extracts data in two ways. The opportunistic Self::extract method returns any ready data, but doesn’t need to produce partial outputs. In contrast, Self::finish needs to produce all outputs, even partial ones. Caller should repeatedly call the functions to drain pending or finished data.

The caller should consume the containers returned by Self::extract and Self::finish. Implementations can recycle buffers, but should ensure that they clear any remaining elements.

For example, a consolidating builder can aggregate differences in-place, but it has to ensure that it preserves the intended information.

The trait does not prescribe any specific ordering guarantees, and each implementation can decide to represent a push order for extract and finish, or not.

Required Associated Types§

source

type Container: Container + Clone + 'static

The container type we’re building.

Required Methods§

source

fn extract(&mut self) -> Option<&mut Self::Container>

Extract assembled containers, potentially leaving unfinished data behind. Can be called repeatedly, for example while the caller can send data.

Returns a Some if there is data ready to be shipped, and None otherwise.

source

fn finish(&mut self) -> Option<&mut Self::Container>

Extract assembled containers and any unfinished data. Should be called repeatedly until it returns None.

Provided Methods§

source

fn partition<I>( container: &mut Self::Container, builders: &mut [Self], index: I, )
where Self: for<'a> PushInto<<Self::Container as Container>::Item<'a>>, Self::Container: SizableContainer, I: for<'a> FnMut(&<Self::Container as Container>::Item<'a>) -> usize,

Partitions container among builders, using the function index to direct items.

Object Safety§

This trait is not object safe.

Implementors§