use crate::{Error, Result};
mod alloc;
mod core;
mod heapless;
mod intx;
mod macaddr;
pub trait FromLeStream: Sized {
fn from_le_stream<T>(bytes: T) -> Option<Self>
where
T: Iterator<Item = u8>;
fn from_le_stream_exact<T>(mut bytes: T) -> Result<Self>
where
T: Iterator<Item = u8>,
{
let instance = Self::from_le_stream(&mut bytes).ok_or(Error::UnexpectedEndOfStream)?;
if let Some(next_byte) = bytes.next() {
Err(Error::StreamNotExhausted {
instance,
next_byte,
})
} else {
Ok(instance)
}
}
fn from_le_slice(bytes: &[u8]) -> Result<Self> {
Self::from_le_stream_exact(bytes.iter().copied())
}
}