pub trait FromReader: Sized {
// Required method
fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read;
}Expand description
Marks a type as able to be deserialized from a reader.
If you are implementing this trait, make sure tora’s derive macros are inapplicable to your use case.
§Examples
use std::io;
use std::io::Read;
use tora::read::{FromReader, ToraRead};
struct CustomVec {
extended_capacity: u32,
content: Vec<u8>
}
impl FromReader for CustomVec {
fn from_reader<R>(r: &mut R) -> io::Result<Self>
where
R: Read,
{
Ok(Self {
extended_capacity: r.reads()?,
content: r.reads()?
})
}
}Required Methods§
fn from_reader<R>(r: &mut R) -> Result<Self>where
R: Read,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl FromReader for bool
impl FromReader for bool
Source§impl FromReader for char
impl FromReader for char
Source§fn from_reader<R>(r: &mut R) -> Result<Self>where
R: Read,
fn from_reader<R>(r: &mut R) -> Result<Self>where
R: Read,
Reads a character from this reader.
Returns ErrorKind::InvalidData if the read u32 cannot be converted to a char.
Source§impl FromReader for f32
impl FromReader for f32
Source§impl FromReader for f64
impl FromReader for f64
Source§impl FromReader for i8
impl FromReader for i8
Source§impl FromReader for i16
impl FromReader for i16
Source§impl FromReader for i32
impl FromReader for i32
Source§impl FromReader for i64
impl FromReader for i64
Source§impl FromReader for i128
impl FromReader for i128
Source§impl FromReader for u8
impl FromReader for u8
Source§impl FromReader for u16
impl FromReader for u16
Source§impl FromReader for u32
impl FromReader for u32
Source§impl FromReader for u64
impl FromReader for u64
Source§impl FromReader for u128
impl FromReader for u128
Source§impl FromReader for ()
impl FromReader for ()
Source§impl FromReader for usize
impl FromReader for usize
Source§impl FromReader for String
impl FromReader for String
Source§fn from_reader<R>(r: &mut R) -> Result<Self>where
R: Read,
fn from_reader<R>(r: &mut R) -> Result<Self>where
R: Read,
Read a UTF-8 string from this reader.
Reads until a NUL 0x00 byte is encountered. Does not include the terminating byte.
Returns ErrorKind::InvalidData if the received message is not valid UTF-8.
Source§impl<T> FromReader for Option<T>where
T: FromReader,
impl<T> FromReader for Option<T>where
T: FromReader,
Source§impl<T> FromReader for Box<T>where
T: FromReader,
impl<T> FromReader for Box<T>where
T: FromReader,
Source§impl<T> FromReader for Vec<T>where
T: FromReader,
Available on crate feature dyn_impl only.
impl<T> FromReader for Vec<T>where
T: FromReader,
Available on crate feature
dyn_impl only.