Skip to main content

Assembler

Struct Assembler 

Source
pub struct Assembler { /* private fields */ }
Expand description

A buffer (re)assembler.

Currently, up to a hardcoded limit of 4 or 32 holes can be tracked in the buffer.

Implementations§

Source§

impl Assembler

Source

pub const fn new() -> Assembler

Create a new buffer assembler.

Source

pub fn clear(&mut self)

Source

pub fn peek_front(&self) -> usize

Return length of the front contiguous range without removing it from the assembler

Source

pub fn is_empty(&self) -> bool

Return whether the assembler contains no data.

Source

pub fn add( &mut self, offset: usize, size: usize, ) -> Result<(), TooManyHolesError>

Add a new contiguous range to the assembler, or return Err(TooManyHolesError) if too many discontinuities are already recorded.

Source

pub fn remove_front(&mut self) -> usize

Remove a contiguous range from the front of the assembler. If no such range, return 0.

Source

pub fn add_then_remove_front( &mut self, offset: usize, size: usize, ) -> Result<usize, TooManyHolesError>

Add a segment, then remove_front.

This is equivalent to calling add then remove_front individually, except it’s guaranteed to not fail when offset = 0. This is required for TCP: we must never drop the next expected segment, or the protocol might get stuck.

Source

pub fn iter_data(&self) -> impl Iterator<Item = (usize, usize)> + '_

Iterate over all of the contiguous data ranges.

Returns (offset, size) tuples for each contiguous data range, where offset is relative to the start of the assembler.

Data Hole Data |— 100 —|— 200 —|— 100 —|

Would return the ranges: (0, 100), (300, 400)

Trait Implementations§

Source§

impl Clone for Assembler

Source§

fn clone(&self) -> Assembler

Returns a duplicate of the value. Read more
1.0.0 (const: unstable)§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Assembler

Source§

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

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

impl Display for Assembler

Source§

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

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

impl Eq for Assembler

Source§

impl PartialEq for Assembler

Source§

fn eq(&self, other: &Assembler) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable)§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Assembler

Auto Trait Implementations§

§

impl Freeze for Assembler

§

impl RefUnwindSafe for Assembler

§

impl Send for Assembler

§

impl Sync for Assembler

§

impl Unpin for Assembler

§

impl UnsafeUnpin for Assembler

§

impl UnwindSafe for Assembler

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.