Trait nuts_bytes::FromBytes
source · pub trait FromBytes<E: TakeBytesError>where
Self: Sized,{
// Required method
fn from_bytes<TB: TakeBytes>(source: &mut TB) -> Result<Self, E>;
}
Expand description
Trait that supports reading datatypes from a binary data stream.
Datatypes that implements this trait can be read from a binary data stream.
Required Methods§
sourcefn from_bytes<TB: TakeBytes>(source: &mut TB) -> Result<Self, E>
fn from_bytes<TB: TakeBytes>(source: &mut TB) -> Result<Self, E>
Reads data from the given source
.
Reads as much as necessary from source
. The method deserializes the
instance and returns it.
Errors
If not enough data are available in source
, the
TakeBytes::take_bytes()
call returns a TakeBytesError::eof()
error, which should be simply forwarded.
Custom errors can be defined in the E
generic. See the
TakeBytes
implementation in String
for an example.
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl<E: TakeBytesError> FromBytes<E> for bool
impl<E: TakeBytesError> FromBytes<E> for bool
source§impl<E: TakeBytesError> FromBytes<E> for f32
impl<E: TakeBytesError> FromBytes<E> for f32
source§impl<E: TakeBytesError> FromBytes<E> for f64
impl<E: TakeBytesError> FromBytes<E> for f64
source§impl<E: TakeBytesError> FromBytes<E> for i8
impl<E: TakeBytesError> FromBytes<E> for i8
source§impl<E: TakeBytesError> FromBytes<E> for i16
impl<E: TakeBytesError> FromBytes<E> for i16
source§impl<E: TakeBytesError> FromBytes<E> for i32
impl<E: TakeBytesError> FromBytes<E> for i32
source§impl<E: TakeBytesError> FromBytes<E> for i64
impl<E: TakeBytesError> FromBytes<E> for i64
source§impl<E: TakeBytesError> FromBytes<E> for u8
impl<E: TakeBytesError> FromBytes<E> for u8
source§impl<E: TakeBytesError> FromBytes<E> for u16
impl<E: TakeBytesError> FromBytes<E> for u16
source§impl<E: TakeBytesError> FromBytes<E> for u32
impl<E: TakeBytesError> FromBytes<E> for u32
source§impl<E: TakeBytesError> FromBytes<E> for u64
impl<E: TakeBytesError> FromBytes<E> for u64
source§impl<E: TakeBytesError> FromBytes<E> for usize
impl<E: TakeBytesError> FromBytes<E> for usize
source§impl<E: TakeBytesError, FB: Copy + Default + FromBytes<E>, const COUNT: usize> FromBytes<E> for [FB; COUNT]
impl<E: TakeBytesError, FB: Copy + Default + FromBytes<E>, const COUNT: usize> FromBytes<E> for [FB; COUNT]
source§impl<E: TakeCharError> FromBytes<E> for char
impl<E: TakeCharError> FromBytes<E> for char
source§impl<E: TakeStringError> FromBytes<E> for String
impl<E: TakeStringError> FromBytes<E> for String
Converts a byte stream into a string.
The assigned error type is derived from TakeStringError
, so the string
conversion can be invalid as well.