pub(crate) struct FrontBackVecBuilder<T> {
vec: Vec<T>,
capacity: usize,
front_len: usize,
back_len: usize,
}Expand description
Builds a Vec of a fixed length that is known up front by pushing items to either its front or its back.
Items pushed to the front end up at the start of the Vec in the order that they were pushed. Items pushed to the
back end up at the end of the Vec in the reverse of the order that they were pushed. This allows a list of items
to be partitioned into two groups in a single pass and with a single allocation.
Exactly capacity items must be pushed before calling into_vec, which panics otherwise.
If the FrontBackVecBuilder is dropped before then (or if too many items are pushed), then items that were
pushed to it are leaked rather than dropped.
Fields§
§vec: Vec<T>The underlying storage. Its length is kept at zero until into_vec is called, and its allocated capacity
is at least capacity.
capacity: usizeThe total number of items that the Vec will contain
front_len: usizeThe number of items pushed to the front. The slots 0..front_len are initialized.
back_len: usizeThe number of items pushed to the back. The slots (capacity - back_len)..capacity are initialized.
Implementations§
Source§impl<T> FrontBackVecBuilder<T>
impl<T> FrontBackVecBuilder<T>
Sourcepub(crate) fn with_capacity(capacity: usize) -> Self
pub(crate) fn with_capacity(capacity: usize) -> Self
Create a new FrontBackVecBuilder that will contain exactly capacity items
Sourcepub(crate) fn push_front(&mut self, value: T)
pub(crate) fn push_front(&mut self, value: T)
Add an item after the items that have already been pushed to the front.
Pushing more than capacity items in total is not checked here: it either panics or overwrites (and leaks)
a previously pushed item, and then causes into_vec to panic.