[][src]Trait read_from::WriteTo

pub trait WriteTo {
    type Error;
    fn write_to<W: Write>(&self, output: W) -> Result<usize, Self::Error>;
}

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]);

Associated Types

type Error

What error can happen when trying to write?

Loading content...

Required methods

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.

Loading content...

Implementations on Foreign Types

impl WriteTo for u8[src]

type Error = Error

impl WriteTo for i8[src]

type Error = Error

Loading content...

Implementors

impl WriteTo for BigEndian<f32>[src]

type Error = Error

impl WriteTo for BigEndian<f64>[src]

type Error = Error

impl WriteTo for BigEndian<i8>[src]

type Error = Error

impl WriteTo for BigEndian<i16>[src]

type Error = Error

impl WriteTo for BigEndian<i32>[src]

type Error = Error

impl WriteTo for BigEndian<i64>[src]

type Error = Error

impl WriteTo for BigEndian<i128>[src]

type Error = Error

impl WriteTo for BigEndian<u8>[src]

type Error = Error

impl WriteTo for BigEndian<u16>[src]

type Error = Error

impl WriteTo for BigEndian<u32>[src]

type Error = Error

impl WriteTo for BigEndian<u64>[src]

type Error = Error

impl WriteTo for BigEndian<u128>[src]

type Error = Error

impl WriteTo for LittleEndian<f32>[src]

type Error = Error

impl WriteTo for LittleEndian<f64>[src]

type Error = Error

impl WriteTo for LittleEndian<i8>[src]

type Error = Error

impl WriteTo for LittleEndian<i16>[src]

type Error = Error

impl WriteTo for LittleEndian<i32>[src]

type Error = Error

impl WriteTo for LittleEndian<i64>[src]

type Error = Error

impl WriteTo for LittleEndian<i128>[src]

type Error = Error

impl WriteTo for LittleEndian<u8>[src]

type Error = Error

impl WriteTo for LittleEndian<u16>[src]

type Error = Error

impl WriteTo for LittleEndian<u32>[src]

type Error = Error

impl WriteTo for LittleEndian<u64>[src]

type Error = Error

impl WriteTo for LittleEndian<u128>[src]

type Error = Error

impl WriteTo for NativeEndian<f32>[src]

type Error = Error

impl WriteTo for NativeEndian<f64>[src]

type Error = Error

impl WriteTo for NativeEndian<i8>[src]

type Error = Error

impl WriteTo for NativeEndian<i16>[src]

type Error = Error

impl WriteTo for NativeEndian<i32>[src]

type Error = Error

impl WriteTo for NativeEndian<i64>[src]

type Error = Error

impl WriteTo for NativeEndian<i128>[src]

type Error = Error

impl WriteTo for NativeEndian<u8>[src]

type Error = Error

impl WriteTo for NativeEndian<u16>[src]

type Error = Error

impl WriteTo for NativeEndian<u32>[src]

type Error = Error

impl WriteTo for NativeEndian<u64>[src]

type Error = Error

impl WriteTo for NativeEndian<u128>[src]

type Error = Error

Loading content...