Struct bin_pool::BinPool

source ·
pub struct BinPool { /* private fields */ }
Expand description

An append-only pool of auto-overlapping binary slices.

In use, you add binary slices one at a time and it will attempt to create maximum overlapping. Currently, it only guarantees that supersets and subsets will overlap. It’s theoretically possible to do cross-slice overlapping, but this would be complex and even more expensive.

Slices added to the pool are guaranteed to remain in insertion order. Moreover, the collection is append-only, so once a slice is added it will remain at the same index for the lifetime of the BinPool.

Implementations§

source§

impl BinPool

source

pub fn new() -> Self

Constructs an empty pool.

source

pub fn add<'a, T>(&mut self, value: T) -> usizewhere T: Into<Cow<'a, [u8]>>,

Adds the specified slice to the pool. If an equivalent slice already exists, does nothing and returns the index of the pre-existing slice; otherwise, adds value as a new slice and returns its (new) slice index.

If you are working with strings, you may find str::as_bytes and [String::into_bytes] useful.

source

pub fn clear(&mut self)

Removes all content from the pool. This is the only non-append-only operation, and is just meant to support resource reuse.

source

pub fn len(&self) -> usize

Gets the number of (distinct) slices contained in the pool.

source

pub fn is_empty(&self) -> bool

Checks if the pool is empty.

source

pub fn iter(&self) -> Iter<'_>

Iterates over all (distinct) slices contained in the pool in insertion order.

source

pub fn get(&self, index: usize) -> Option<&[u8]>

Gets the slice at the specified index, or None if index is not a valid slice index returned by BinPool::add.

source

pub fn bytes(&self) -> usize

Gets the total number of bytes from (distinct) slices that were added to the pool. Note that the space needed to represent these slices may be significantly smaller (see BinPool::backing_bytes).

source

pub fn backing_bytes(&self) -> usize

Gets the total number of bytes backing the stored slices.

source

pub fn as_backing(&self) -> (&Vec<Vec<u8>>, &Vec<SliceInfo>)

Gets a reference to the backing data.

source

pub fn into_backing(self) -> (Vec<Vec<u8>>, Vec<SliceInfo>)

Gets the backing data.

Trait Implementations§

source§

impl Clone for BinPool

source§

fn clone(&self) -> BinPool

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BinPool

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for BinPool

source§

fn default() -> BinPool

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.