Trait handy_io::io::WriteTo [] [src]

pub trait WriteTo<W: Write>: Pattern {
    type Future: Future<Item = (W, Self::Value), Error = (W, Error)>;
    fn lossless_write_to(self, writer: W) -> Self::Future;

    fn write_to(self, writer: W) -> LossyWriteTo<W, Self::Future> { ... }
    fn sync_write_to(self, writer: W) -> Result<Self::Value> { ... }
    fn boxed(self) -> BoxWriteTo<W, Self::Value>
    where
        Self: Send + 'static,
        Self::Future: Send + 'static
, { ... } }

The WriteTo trait allows for writing a value of the pattern to a sink asynchronously.

Notice

For executing asynchronously, we assume the writer W returns the std::io::ErrorKind::WouldBlock error if a write operation would be about to block.

Associated Types

The future to write a value of the pattern to W.

Required Methods

Creates a future instance to write a value of the pattern to writer.

Provided Methods

Creates a future instance to write a value of the pattern to writer.

If the execution of the future fails, the writer will be dropped.

Example

extern crate futures;
extern crate handy_io;

use futures::Future;
use handy_io::io::WriteTo;
use handy_io::pattern::{Pattern, Endian};

fn main() {
    let pattern = (1u8, 2u16.be());
    let future = pattern.write_to(Vec::new());
    assert_eq!(future.wait().unwrap().0, [1, 0, 2]);
}

Scynchronously writing a value of the pattern to writer.

Example

use handy_io::io::WriteTo;
use handy_io::pattern::{Pattern, Endian};

let mut buf = [0; 3];
let pattern = (1u8, 2u16.be());
pattern.sync_write_to(&mut &mut buf[..]).unwrap();
assert_eq!(buf, [1, 0, 2]);

Returns the boxed version of this pattern.

Implementors