Skip to main content

FromLeStream

Trait FromLeStream 

Source
pub trait FromLeStream: Sized {
    // Required method
    fn from_le_stream<T>(bytes: T) -> Option<Self>
       where T: Iterator<Item = u8>;

    // Provided methods
    fn from_le_stream_exact<T>(bytes: T) -> Result<Self>
       where T: Iterator<Item = u8> { ... }
    fn from_le_slice(bytes: &[u8]) -> Result<Self> { ... }
}
Expand description

Parses a value from a stream of little-endian bytes.

Implementations read exactly the bytes required to construct Self and leave any remaining bytes in the input iterator. Use from_le_stream_exact when trailing bytes should be treated as an error.

Required Methods§

Source

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Parses a value from the front of a little-endian byte stream.

The method returns None when the stream ends before a complete value can be decoded. Implementations may leave unread bytes in bytes after successfully decoding one value.

§Examples
use le_stream::FromLeStream;

let mut bytes = [0x34, 0x12, 0xFF].into_iter();

assert_eq!(u16::from_le_stream(&mut bytes), Some(0x1234));
assert_eq!(bytes.next(), Some(0xFF));

Provided Methods§

Source

fn from_le_stream_exact<T>(bytes: T) -> Result<Self>
where T: Iterator<Item = u8>,

Parses a value from a little-endian byte stream and requires exhaustion.

§Errors

Returns Error::UnexpectedEndOfStream if the stream ends before a complete value can be decoded, or Error::StreamNotExhausted if a value was decoded but more bytes remain.

Source

fn from_le_slice(bytes: &[u8]) -> Result<Self>

Parses a value from a little-endian byte slice and requires exhaustion.

§Errors

Returns an Error if the slice is too short or contains bytes after the decoded value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FromLeStream for ()

Source§

fn from_le_stream<T>(_: T) -> Option<Self>
where T: Iterator<Item = u8>,

This is guaranteed to always return Some(()).

Source§

impl FromLeStream for bool

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for f32

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for f64

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for i8

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for i16

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for i32

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for i64

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for i128

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for isize

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for u8

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = Self>,

Source§

impl FromLeStream for u16

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for u32

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for u64

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for u128

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl FromLeStream for usize

Source§

fn from_le_stream<T>(bytes: T) -> Option<Self>
where T: Iterator<Item = u8>,

Source§

impl<T, const SIZE: usize> FromLeStream for [T; SIZE]
where T: FromLeStream,

Source§

fn from_le_stream<I>(bytes: I) -> Option<Self>
where I: Iterator<Item = u8>,

Source§

impl<T> FromLeStream for Option<T>
where T: FromLeStream,

Source§

fn from_le_stream<I>(bytes: I) -> Option<Self>
where I: Iterator<Item = u8>,

This is guaranteed to always return Some(Option<T>).

Source§

impl<T> FromLeStream for PhantomData<T>

Source§

fn from_le_stream<I>(_: I) -> Option<Self>
where I: Iterator<Item = u8>,

This is guaranteed to always return Some(PhantomData<T>).

Source§

impl<T> FromLeStream for Range<T>
where T: FromLeStream,

Source§

fn from_le_stream<I>(bytes: I) -> Option<Self>
where I: Iterator<Item = u8>,

Source§

impl<T> FromLeStream for RangeInclusive<T>
where T: FromLeStream,

Source§

fn from_le_stream<I>(bytes: I) -> Option<Self>
where I: Iterator<Item = u8>,

Implementors§