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
type Future: Future<Item = (W, Self::Value), Error = (W, Error)>
The future to write a value of the pattern to W
.
Required Methods
fn lossless_write_to(self, writer: W) -> Self::Future
Creates a future instance to write a value of the pattern to writer
.
Provided Methods
fn write_to(self, writer: W) -> LossyWriteTo<W, Self::Future>
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]); }
fn sync_write_to(self, writer: W) -> Result<Self::Value>
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]);
fn boxed(self) -> BoxWriteTo<W, Self::Value> where
Self: Send + 'static,
Self::Future: Send + 'static,
Self: Send + 'static,
Self::Future: Send + 'static,
Returns the boxed version of this pattern.
Implementors
impl<W: Write> WriteTo<W> for Flush
impl<W: Write, B: AsRef<[u8]>> WriteTo<W> for Buf<B>
impl<W: Write, B: AsRef<[u8]>> WriteTo<W> for PartialBuf<B>
impl<W: Write> WriteTo<W> for Vec<u8>
impl<W: Write> WriteTo<W> for String
impl<W: Write, B: AsRef<[u8]>> WriteTo<W> for Window<B>
impl<W: Write> WriteTo<W> for u8
impl<W: Write> WriteTo<W> for i8
impl<W: Write> WriteTo<W> for u16
impl<W: Write> WriteTo<W> for BE<u16>
impl<W: Write> WriteTo<W> for LE<u16>
impl<W: Write> WriteTo<W> for i16
impl<W: Write> WriteTo<W> for BE<i16>
impl<W: Write> WriteTo<W> for LE<i16>
impl<W: Write> WriteTo<W> for U24
impl<W: Write> WriteTo<W> for BE<U24>
impl<W: Write> WriteTo<W> for LE<U24>
impl<W: Write> WriteTo<W> for I24
impl<W: Write> WriteTo<W> for BE<I24>
impl<W: Write> WriteTo<W> for LE<I24>
impl<W: Write> WriteTo<W> for u32
impl<W: Write> WriteTo<W> for BE<u32>
impl<W: Write> WriteTo<W> for LE<u32>
impl<W: Write> WriteTo<W> for i32
impl<W: Write> WriteTo<W> for BE<i32>
impl<W: Write> WriteTo<W> for LE<i32>
impl<W: Write> WriteTo<W> for U40
impl<W: Write> WriteTo<W> for BE<U40>
impl<W: Write> WriteTo<W> for LE<U40>
impl<W: Write> WriteTo<W> for I40
impl<W: Write> WriteTo<W> for BE<I40>
impl<W: Write> WriteTo<W> for LE<I40>
impl<W: Write> WriteTo<W> for U48
impl<W: Write> WriteTo<W> for BE<U48>
impl<W: Write> WriteTo<W> for LE<U48>
impl<W: Write> WriteTo<W> for I48
impl<W: Write> WriteTo<W> for BE<I48>
impl<W: Write> WriteTo<W> for LE<I48>
impl<W: Write> WriteTo<W> for U56
impl<W: Write> WriteTo<W> for BE<U56>
impl<W: Write> WriteTo<W> for LE<U56>
impl<W: Write> WriteTo<W> for I56
impl<W: Write> WriteTo<W> for BE<I56>
impl<W: Write> WriteTo<W> for LE<I56>
impl<W: Write> WriteTo<W> for u64
impl<W: Write> WriteTo<W> for BE<u64>
impl<W: Write> WriteTo<W> for LE<u64>
impl<W: Write> WriteTo<W> for i64
impl<W: Write> WriteTo<W> for BE<i64>
impl<W: Write> WriteTo<W> for LE<i64>
impl<W: Write, P0, P1, F> WriteTo<W> for Then<P0, F> where
P0: WriteTo<W>,
P1: WriteTo<W>,
F: FnOnce(Result<P0::Value>) -> P1,impl<W: Write, P0, P1, F> WriteTo<W> for AndThen<P0, F> where
P0: WriteTo<W>,
P1: WriteTo<W>,
F: FnOnce(P0::Value) -> P1,impl<W: Write, P0, P1, F> WriteTo<W> for OrElse<P0, F> where
P0: WriteTo<W>,
P1: WriteTo<W, Value = P0::Value>,
F: FnOnce(Error) -> P1,impl<W: Write, P, F, T> WriteTo<W> for Map<P, F> where
P: WriteTo<W>,
F: FnOnce(P::Value) -> T,impl<W: Write, P0, P1> WriteTo<W> for Chain<P0, P1> where
P0: WriteTo<W>,
P1: WriteTo<W>,impl<W: Write> WriteTo<W> for ()
impl<W: Write, P0, P1> WriteTo<W> for (P0, P1) where
P0: WriteTo<W>,
P1: WriteTo<W>,impl<W: Write, P0, P1, P2> WriteTo<W> for (P0, P1, P2) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,impl<W: Write, P0, P1, P2, P3> WriteTo<W> for (P0, P1, P2, P3) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,impl<W: Write, P0, P1, P2, P3, P4> WriteTo<W> for (P0, P1, P2, P3, P4) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,
P4: WriteTo<W>,impl<W: Write, P0, P1, P2, P3, P4, P5> WriteTo<W> for (P0, P1, P2, P3, P4, P5) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,
P4: WriteTo<W>,
P5: WriteTo<W>,impl<W: Write, P0, P1, P2, P3, P4, P5, P6> WriteTo<W> for (P0, P1, P2, P3, P4, P5, P6) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,
P4: WriteTo<W>,
P5: WriteTo<W>,
P6: WriteTo<W>,impl<W: Write, P0, P1, P2, P3, P4, P5, P6, P7> WriteTo<W> for (P0, P1, P2, P3, P4, P5, P6, P7) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,
P4: WriteTo<W>,
P5: WriteTo<W>,
P6: WriteTo<W>,
P7: WriteTo<W>,impl<W: Write, P0, P1, P2, P3, P4, P5, P6, P7, P8> WriteTo<W> for (P0, P1, P2, P3, P4, P5, P6, P7, P8) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,
P4: WriteTo<W>,
P5: WriteTo<W>,
P6: WriteTo<W>,
P7: WriteTo<W>,
P8: WriteTo<W>,impl<W: Write, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> WriteTo<W> for (P0, P1, P2, P3, P4, P5, P6, P7, P8, P9) where
P0: WriteTo<W>,
P1: WriteTo<W>,
P2: WriteTo<W>,
P3: WriteTo<W>,
P4: WriteTo<W>,
P5: WriteTo<W>,
P6: WriteTo<W>,
P7: WriteTo<W>,
P8: WriteTo<W>,
P9: WriteTo<W>,impl<W: Write, A, B, C, D, E, F, G, H> WriteTo<W> for Branch<A, B, C, D, E, F, G, H> where
A: WriteTo<W>,
B: WriteTo<W, Value = A::Value>,
C: WriteTo<W, Value = A::Value>,
D: WriteTo<W, Value = A::Value>,
E: WriteTo<W, Value = A::Value>,
F: WriteTo<W, Value = A::Value>,
G: WriteTo<W, Value = A::Value>,
H: WriteTo<W, Value = A::Value>,impl<W: Write, I, F, T> WriteTo<W> for IterFold<I, F, T> where
I: Iterator,
I::Item: WriteTo<W>,
F: Fn(T, <I::Item as Pattern>::Value) -> T,impl<W: Write, I> WriteTo<W> for Iter<I> where
I: Iterator,
I::Item: WriteTo<W>,impl<W: Write, P> WriteTo<W> for Option<P> where
P: WriteTo<W>,impl<W: Write, T> WriteTo<W> for Result<T>
impl<W: Write, T> WriteTo<W> for BoxWriteTo<W, T>