[][src]Trait bytestream::Streamable

pub trait Streamable: Sized {
    fn read_from<R: Read>(buffer: &mut R, order: ByteOrder) -> Result<Self>;
fn write_to<W: Write>(&self, buffer: &mut W, order: ByteOrder) -> Result<()>; }

The streamable trait allows for reading and writing bytes to and from a buffer.

Example

use std::io::{Read, Result, Write};
use bytestream::*;

pub struct Foo {
    bar: String,
    baz: u32,
}

impl Streamable for Foo {
    fn read_from<R: Read>(buffer: &mut R, order: ByteOrder) -> Result<Self> {
        Ok(Self {
            bar: String::read_from(buffer, order)?,
            baz: u32::read_from(buffer, order)?,
        })
    }
    fn write_to<W: Write>(&self, buffer: &mut W, order: ByteOrder) -> Result<()> {
        self.bar.write_to(buffer, order)?;
        self.baz.write_to(buffer, order)?;
        Ok(())
    }
}

Required methods

fn read_from<R: Read>(buffer: &mut R, order: ByteOrder) -> Result<Self>

Reads something from the specified buffer using the specified byte order.

fn write_to<W: Write>(&self, buffer: &mut W, order: ByteOrder) -> Result<()>

Writes something to the specified buffer using the specified byte order.

Loading content...

Implementations on Foreign Types

impl Streamable for bool[src]

impl Streamable for u64[src]

impl Streamable for u32[src]

impl Streamable for u16[src]

impl Streamable for u8[src]

impl Streamable for i64[src]

impl Streamable for i32[src]

impl Streamable for i16[src]

impl Streamable for i8[src]

impl Streamable for String[src]

impl<T: Streamable> Streamable for Vec<T>[src]

impl<T: Streamable + Eq + Hash, V: Streamable, S: BuildHasher + Default> Streamable for HashMap<T, V, S>[src]

Loading content...

Implementors

Loading content...