Struct assembly

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

A list of contiguous data chunks and holes.

Implementations§

Source§

impl assembly

Source

pub fn new(contigs: &mut [Contig]) -> &mut Self

Create an empty assembly by zeroeing the slice.

Source

pub fn from_slice_unchecked(contigs: &[Contig]) -> &Self

Convert a slice.

Only the tail should consist of contigs without data. This is not critical to memory safety but to correctness.

Source

pub fn from_mut_slice_unchecked(contigs: &mut [Contig]) -> &mut Self

Convert a mutable slice.

Only the tail should consist of contigs without data. This is not critical to memory safety but to correctness.

Source

pub fn is_empty(&self) -> bool

Return whether the assembler contains no more data.

Source

pub fn reduce_front(&mut self) -> u32

Remove any leading bytes.

Can be used to remove leftover bytes after a bounded operation (bounded_add) removed only parts of a fully assembled initial sequence.

§Example
let mut memory: [Contig; 2] = [Contig::default(); 2];
let mut asm = Assembler::new(&mut memory[..]);

// Add four bytes without removing any start bytes.
assert_eq!(asm.bounded_add(0, 4, 0), Ok(0));
// Pop the 4 bytes in a separate operation.
assert_eq!(asm.reduce_front(), 4);
Source

pub fn add(&mut self, start: u32, size: u32) -> Result<u32, ()>

Add a new contiguous range to the assembler.

Returns the number of bytes that became assembled from the range, or Err(()) if it was not possible to store the range. If this operation returns an error then it did not modify the Assembler at all.

§Example
let mut memory: [Contig; 2] = [Contig::default(); 2];
let mut asm = Assembler::new(&mut memory[..]);

// Add four bytes not at the start.
assert_eq!(asm.add(4, 4), Ok(0));
// Add missing four bytes at the start, which assembles the chunk.
assert_eq!(asm.add(0, 4), Ok(8));
Source

pub fn bounded_add( &mut self, start: u32, size: u32, max: u32, ) -> Result<u32, ()>

Add a new contiguous range and then pop at most max assembled bytes.

Returns the number of bytes that were assembled in front, or Err(()) if it was not possible to store the range. If this operation returns an error then it did not modify the Assembler at all.

§Example
let mut memory: [Contig; 2] = [Contig::default(); 2];
let mut asm = Assembler::new(&mut memory[..]);

// Add four bytes not at the start.
assert_eq!(asm.add(4, 4), Ok(0));
// Add the four bytes at the start but do not return them all yet.
assert_eq!(asm.bounded_add(0, 4, 4), Ok(4));
// Now pop the 4 remaining bytes.
assert_eq!(asm.reduce_front(), 4);
Source

pub fn iter<'a>(&'a self) -> AssemblerIter<'a>

Iterate over all of the contiguous data ranges.

This is used in calculating what data ranges have been received. The offset indicates the number of bytes of contiguous data received before the beginnings of this Assembler.

   Data        Hole        Data
|--- 100 ---|--- 200 ---|--- 100 ---|

This would return the ranges: (100, 200), (300, 400)

Trait Implementations§

Source§

impl Debug for assembly

Source§

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

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

impl Display for assembly

Source§

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

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

impl PartialEq for assembly

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for assembly

Source§

impl StructuralPartialEq for assembly

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more