[go: up one dir, main page]

ToraRead

Trait ToraRead 

Source
pub trait ToraRead {
    // Required method
    fn reads<T>(&mut self) -> Result<T>
       where T: FromReader;
}
Expand description

An extension upon the standard Read implementation.

use std::io;
use std::net::TcpStream;
use tora::read::ToraRead;

fn main() -> io::Result<()> {
    let mut stream = TcpStream::connect("127.0.0.1:12345")?;
    let message = stream.reads::<i32>()?;

    println!("{}", message);
    Ok(())
}

Required Methods§

Source

fn reads<T>(&mut self) -> Result<T>
where T: FromReader,

Try to read and deserialize a type from this reader.

use std::io;
use std::net::TcpStream;
use tora::read::ToraRead;

fn main() -> io::Result<()> {
    let mut stream = TcpStream::connect("127.0.0.1:12345")?;

    let date = stream.reads::<u16>()?;
    let employees: Vec<String> = stream.reads()?;

    println!("{date}, {employees:?}");
    Ok(())
}

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.

Implementors§

Source§

impl<R> ToraRead for R
where R: Read,

Available on crate feature read_impl only.