Trait timely::container::ContainerBuilder

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

    // Required methods
    fn push<T>(&mut self, item: T)
       where Self::Container: SizableContainer + PushInto<T>;
    fn push_container(&mut self, container: &mut Self::Container);
    fn extract(&mut self) -> Option<&mut Self::Container>;
    fn finish(&mut self) -> Option<&mut Self::Container>;
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.

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.

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/push_container order for extract and finish, or not.

Required Associated Types§


type Container: Container

The container type we’re building.

Required Methods§


fn push<T>(&mut self, item: T)

Add an item to a container.

The restriction to [SizeableContainer] only exists so that types relying on CapacityContainerBuilder only need to constrain their container to Container instead of SizableContainer, which otherwise would be a pervasive requirement.


fn push_container(&mut self, container: &mut Self::Container)

Push a pre-built container.


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

Extract assembled containers, potentially leaving unfinished data behind.


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

Extract assembled containers and any unfinished data.

Object Safety§

This trait is not object safe.