[go: up one dir, main page]

FromReader

Trait FromReader 

Source
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§

Source

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

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Reads a bool from this reader.

Returns true if the read u8 is not zero.

Source§

impl FromReader for char

Source§

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

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for f64

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for i8

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for i16

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for i32

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for i64

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for i128

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for u8

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for u16

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for u32

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for u64

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for u128

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for ()

Source§

fn from_reader<R>(_r: &mut R) -> Result<Self>
where R: Read,

Immediately returns Ok of unit value.

Source§

impl FromReader for usize

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl FromReader for String

Source§

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,

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Reads a bool and if true, reads and returns Some([T]).

Source§

impl<T> FromReader for Box<T>
where T: FromReader,

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Source§

impl<T> FromReader for Vec<T>
where T: FromReader,

Available on crate feature dyn_impl only.
Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Reads a u32, then reads N amount of [T] into a Vec and returns it.

Source§

impl<T, E> FromReader for Result<T, E>
where T: FromReader, E: FromReader,

Source§

fn from_reader<R>(r: &mut R) -> Result<Result<T, E>>
where R: Read,

Reads a boolean and if true, tries to deserialize the [E] type, else [T].

Source§

impl<T, Z> FromReader for (T, Z)
where T: FromReader, Z: FromReader,

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Reads a tuple of [T] and [Z], respectively.

Source§

impl<T, Z, H> FromReader for (T, Z, H)
where T: FromReader, Z: FromReader, H: FromReader,

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Reads a tuple of [T], [Z], and [H], respectively.

Source§

impl<T, const N: usize> FromReader for [T; N]
where T: FromReader + Copy + Default,

Source§

fn from_reader<R>(r: &mut R) -> Result<Self>
where R: Read,

Reads and deserializes [N] amount of [T].

Implementors§