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§
Sourcefn from_le_stream<T>(bytes: T) -> Option<Self>
fn from_le_stream<T>(bytes: T) -> Option<Self>
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§
Sourcefn from_le_stream_exact<T>(bytes: T) -> Result<Self>
fn from_le_stream_exact<T>(bytes: T) -> Result<Self>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".