pub struct RandomAccessBinaryCollection<'a> { /* private fields */ }Expand description
A version of BinaryCollection with random access to sequences.
Because the binary format underlying BinaryCollection does not
support random access, implementing it requires precomputing memory
offsets for the sequences, and storing them in the struct.
This means RandomAccessBinaryCollection::try_from will have to
perform one full pass through the entire collection to collect the
offsets. Thus, use this class only if you need the random access
functionality.
Note that the because offsets are stored within the struct, it is
not Copy as opposed to BinaryCollection, which is simply a view
over a memory buffer.
§Examples
let mut buffer: Vec<u8> = Vec::new();
encode_u32_sequence(&mut buffer, 3, &[1, 2, 3])?;
encode_u32_sequence(&mut buffer, 1, &[4])?;
encode_u32_sequence(&mut buffer, 3, &[5, 6, 7])?;
let mut collection = RandomAccessBinaryCollection::try_from(&buffer[..])?;
assert_eq!(
collection.get(0).map(|seq| seq.iter().collect::<Vec<_>>()),
Some(vec![1_u32, 2, 3]),
);
assert_eq!(
collection.at(2).iter().collect::<Vec<_>>(),
vec![5_u32, 6, 7],
);
assert_eq!(collection.get(3), None);ⓘ
collection.at(3); // out of boundsImplementations§
Source§impl<'a> RandomAccessBinaryCollection<'a>
impl<'a> RandomAccessBinaryCollection<'a>
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = Result<BinarySequence<'a>, InvalidFormat>>
pub fn iter( &self, ) -> impl Iterator<Item = Result<BinarySequence<'a>, InvalidFormat>>
Returns an iterator over sequences.
Sourcepub fn at(&self, index: usize) -> BinarySequence<'a>
pub fn at(&self, index: usize) -> BinarySequence<'a>
Sourcepub fn get(&self, index: usize) -> Option<BinarySequence<'a>>
pub fn get(&self, index: usize) -> Option<BinarySequence<'a>>
Returns the sequence at the given index or None if out of bounds.
Trait Implementations§
Source§impl<'a> Clone for RandomAccessBinaryCollection<'a>
impl<'a> Clone for RandomAccessBinaryCollection<'a>
Source§fn clone(&self) -> RandomAccessBinaryCollection<'a>
fn clone(&self) -> RandomAccessBinaryCollection<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for RandomAccessBinaryCollection<'a>
impl<'a> Debug for RandomAccessBinaryCollection<'a>
Auto Trait Implementations§
impl<'a> Freeze for RandomAccessBinaryCollection<'a>
impl<'a> RefUnwindSafe for RandomAccessBinaryCollection<'a>
impl<'a> Send for RandomAccessBinaryCollection<'a>
impl<'a> Sync for RandomAccessBinaryCollection<'a>
impl<'a> Unpin for RandomAccessBinaryCollection<'a>
impl<'a> UnwindSafe for RandomAccessBinaryCollection<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more