pub struct assembly { /* private fields */ }Expand description
A list of contiguous data chunks and holes.
Implementations§
Source§impl assembly
impl assembly
Sourcepub fn new(contigs: &mut [Contig]) -> &mut Self
pub fn new(contigs: &mut [Contig]) -> &mut Self
Create an empty assembly by zeroeing the slice.
Sourcepub fn from_slice_unchecked(contigs: &[Contig]) -> &Self
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.
Sourcepub fn from_mut_slice_unchecked(contigs: &mut [Contig]) -> &mut Self
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.
Sourcepub fn reduce_front(&mut self) -> u32
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);Sourcepub fn add(&mut self, start: u32, size: u32) -> Result<u32, ()>
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));Sourcepub fn bounded_add(
&mut self,
start: u32,
size: u32,
max: u32,
) -> Result<u32, ()>
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);Sourcepub fn iter<'a>(&'a self) -> AssemblerIter<'a> ⓘ
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)