pub struct Lots<T> { /* private fields */ }
Expand description
A collection of T
, organized by generational LotId
s.
This data type allows storing data of any type and receiving a LotId
that can later be used to look up the data.
This data type cannot hold more than 2^48 items, due how LotId
s are
allocated.
Generation Checks
A LotId
contains 16 bits representing a lot’s generation. Each time a
lot is updated, the lot’s generation is incremented (with wrapping).
The lot’s generation is checked when retrieving data using a LotId
. If a
generation mismatch is found, the data will not be returned.
While the chances of generation collision may be low, this is not a perfect
check. Care should still be taken to ensure stale LotId
s aren’t used
when other ways of validating the data don’t exist.
Implementations§
source§impl<T> Lots<T>
impl<T> Lots<T>
sourcepub fn with_capacity(initial_capacity: usize) -> Self
pub fn with_capacity(initial_capacity: usize) -> Self
Returns an empty collection that can hold initial_capacity
values
without reallocation.
sourcepub fn push(&mut self, value: T) -> LotId
pub fn push(&mut self, value: T) -> LotId
Adds value
to the collection, returning the value’s unique LotId
.
sourcepub fn drain(&mut self) -> Drain<'_, T, DrainAll> ⓘ
pub fn drain(&mut self) -> Drain<'_, T, DrainAll> ⓘ
Returns an iterator that returns all the contained values in this collection as they’re removed from the collection.
Dropping the iterator will still result in the elements being removed.
sourcepub fn drain_filter<Filter>(&mut self, filter: Filter) -> Drain<'_, T, Filter> ⓘ
pub fn drain_filter<Filter>(&mut self, filter: Filter) -> Drain<'_, T, Filter> ⓘ
Returns an iterator that invokes filter
for each item in the
collection. If filter
returns true for that value, it will be removed
and returned from the iterator. When false is returned, the value is
kept in the collection.
Dropping the iterator will still result in the filtered elements being removed.