WriteTo

Trait WriteTo 

Source
pub trait WriteTo {
    type Error;

    // Required method
    fn write_to<W: Write>(&self, output: W) -> Result<usize, Self::Error>;
}
Expand description

Used to serialize types into an output stream (i.e. a Write implementation).

§Example

This implements WriteTo for a simple TinyRational struct.

use read_from::WriteTo;
use std::io::{self, Write};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TinyRational {
   numer: i8,
   denom: u8
}

impl WriteTo for TinyRational {
   type Error = io::Error;

   fn write_to<W: Write>(&self, mut out: W) -> Result<usize, Self::Error> {
      out.write_all(&[self.numer as u8, self.denom]).and(Ok(2))
   }
}

let mut buf = Vec::new();
TinyRational { numer: 3, denom: 4 }.write_to(&mut buf).unwrap();

assert_eq!(buf, &[3, 4]);

Required Associated Types§

Source

type Error

What error can happen when trying to write?

Required Methods§

Source

fn write_to<W: Write>(&self, output: W) -> Result<usize, Self::Error>

Attempts to write self to the given output stream, returning the number of bytes written on success.

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 WriteTo for i8

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for u8

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 0]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 1]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 2]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 3]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 4]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 5]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 6]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 7]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 8]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 9]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 10]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 11]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 12]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 13]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 14]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 15]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 16]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 17]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 18]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 19]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 20]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 21]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 22]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 23]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 24]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 25]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 26]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 27]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 28]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 29]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 30]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 31]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 32]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 50]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 64]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 100]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 128]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 250]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 256]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 500]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 512]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 1000]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 1024]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 2048]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 2500]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 4096]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 5000]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 8192]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Source§

impl WriteTo for [u8; 10000]

Source§

type Error = Error

Source§

fn write_to<W: Write>(&self, out: W) -> Result<usize, Self::Error>

Implementors§

Source§

impl WriteTo for BigEndian<f32>

Source§

impl WriteTo for BigEndian<f64>

Source§

impl WriteTo for BigEndian<i8>

Source§

impl WriteTo for BigEndian<i16>

Source§

impl WriteTo for BigEndian<i32>

Source§

impl WriteTo for BigEndian<i64>

Source§

impl WriteTo for BigEndian<i128>

Source§

impl WriteTo for BigEndian<isize>

Source§

impl WriteTo for BigEndian<u8>

Source§

impl WriteTo for BigEndian<u16>

Source§

impl WriteTo for BigEndian<u32>

Source§

impl WriteTo for BigEndian<u64>

Source§

impl WriteTo for BigEndian<u128>

Source§

impl WriteTo for BigEndian<usize>

Source§

impl WriteTo for LittleEndian<f32>

Source§

impl WriteTo for LittleEndian<f64>

Source§

impl WriteTo for LittleEndian<i8>

Source§

impl WriteTo for LittleEndian<i16>

Source§

impl WriteTo for LittleEndian<i32>

Source§

impl WriteTo for LittleEndian<i64>

Source§

impl WriteTo for LittleEndian<i128>

Source§

impl WriteTo for LittleEndian<isize>

Source§

impl WriteTo for LittleEndian<u8>

Source§

impl WriteTo for LittleEndian<u16>

Source§

impl WriteTo for LittleEndian<u32>

Source§

impl WriteTo for LittleEndian<u64>

Source§

impl WriteTo for LittleEndian<u128>

Source§

impl WriteTo for LittleEndian<usize>

Source§

impl WriteTo for NativeEndian<f32>

Source§

impl WriteTo for NativeEndian<f64>

Source§

impl WriteTo for NativeEndian<i8>

Source§

impl WriteTo for NativeEndian<i16>

Source§

impl WriteTo for NativeEndian<i32>

Source§

impl WriteTo for NativeEndian<i64>

Source§

impl WriteTo for NativeEndian<i128>

Source§

impl WriteTo for NativeEndian<isize>

Source§

impl WriteTo for NativeEndian<u8>

Source§

impl WriteTo for NativeEndian<u16>

Source§

impl WriteTo for NativeEndian<u32>

Source§

impl WriteTo for NativeEndian<u64>

Source§

impl WriteTo for NativeEndian<u128>

Source§

impl WriteTo for NativeEndian<usize>