pub struct BytesSlab { /* private fields */ }
Expand description

A large binary allocation for writing and sharing.

A bytes slab wraps a Bytes and maintains a valid (written) length, and supports writing after this valid length, and extracting Bytes up to this valid length. Extracted bytes are enqueued and checked for uniqueness in order to recycle them (once all shared references are dropped).

Implementations§

source§

impl BytesSlab

source

pub fn new(shift: usize) -> Self

Allocates a new BytesSlab with an initial size determined by a shift.

source

pub fn empty(&mut self) -> &mut [u8]

The empty region of the slab.

source

pub fn valid(&mut self) -> &mut [u8]

The valid region of the slab.

source

pub fn make_valid(&mut self, bytes: usize)

Marks the next bytes bytes as valid.

source

pub fn extract(&mut self, bytes: usize) -> Bytes

Extracts the first bytes valid bytes.

source

pub fn ensure_capacity(&mut self, capacity: usize)

Ensures that self.empty().len() is at least capacity.

This method may retire the current buffer if it does not have enough space, in which case it will copy any remaining contents into a new buffer. If this would not create enough free space, the shift is increased until it is sufficient.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where 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 T
where 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.