[][src]Struct ciff::BinaryCollection

pub struct BinaryCollection<'a> { /* fields omitted */ }

Represents a single binary collection.

A binary collection is a series of sequences, each starting with a 4-byte length, followed by this many 4-byte values.

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])?;

// Binary collection is actually an iterator
let mut collection = BinaryCollection::try_from(&buffer[..])?;
assert_eq!(
    collection.next().unwrap().map(|seq| seq.iter().collect::<Vec<_>>()).ok(),
    Some(vec![1_u32, 2, 3])
);
assert_eq!(
    collection.next().unwrap().map(|seq| seq.iter().collect::<Vec<_>>()).ok(),
    Some(vec![4_u32])
);
assert_eq!(
    collection.next().unwrap().map(|seq| seq.iter().collect::<Vec<_>>()).ok(),
    Some(vec![5_u32, 6, 7])
);

// Must create a new collection to iterate again.
let collection = BinaryCollection::try_from(&buffer[..])?;
let elements: Result<Vec<_>, InvalidFormat> = collection
    .map(|sequence| Ok(sequence?.iter().collect::<Vec<_>>()))
    .collect();
assert_eq!(elements?, vec![vec![1_u32, 2, 3], vec![4], vec![5, 6, 7]]);

Trait Implementations

impl<'a> Iterator for BinaryCollection<'a>[src]

type Item = Result<BinarySequence<'a>, InvalidFormat>

The type of the elements being iterated over.

impl<'a> TryFrom<&'a [u8]> for BinaryCollection<'a>[src]

type Error = InvalidFormat

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'a> RefUnwindSafe for BinaryCollection<'a>

impl<'a> Send for BinaryCollection<'a>

impl<'a> Sync for BinaryCollection<'a>

impl<'a> Unpin for BinaryCollection<'a>

impl<'a> UnwindSafe for BinaryCollection<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<S, T> ProgressIterator for T where
    T: Iterator<Item = S>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.