Trait handy_io::io::ReadFrom
[−]
[src]
pub trait ReadFrom<R: Read>: Pattern { type Future: Future<Item = (R, Self::Value), Error = (R, Error)>; fn lossless_read_from(self, reader: R) -> Self::Future; fn read_from(self, reader: R) -> LossyReadFrom<R, Self::Future> { ... } fn sync_read_from(self, reader: R) -> Result<Self::Value> { ... } fn boxed(self) -> BoxReadFrom<R, Self::Value>
where
Self: Send + 'static,
Self::Future: Send + 'static, { ... } }
The ReadFrom
trait allows for reading
a value of the pattern from a source asynchronously.
Notice
For executing asynchronously, we assume the reader R
returns the std::io::ErrorKind::WouldBlock
error
if a read operation would be about to block.
Associated Types
type Future: Future<Item = (R, Self::Value), Error = (R, Error)>
The future to read a value of the pattern from R
.
Required Methods
fn lossless_read_from(self, reader: R) -> Self::Future
Creates a future instance to read a value of the pattern from reader
.
Provided Methods
fn read_from(self, reader: R) -> LossyReadFrom<R, Self::Future>
Creates a future instance to read a value of the pattern from reader
.
If the execution of the future fails, the reader
will be dropped.
Example
extern crate futures; extern crate handy_io; use handy_io::io::ReadFrom; use handy_io::pattern::{Pattern, Endian}; use handy_io::pattern::read::{U8, U16}; use futures::Future; fn main() { let mut input = &[1, 0, 2][..]; let pattern = (U8, U16.be()); let future = pattern.read_from(&mut input); assert_eq!(future.wait().unwrap().1, (1, 2)); }
fn sync_read_from(self, reader: R) -> Result<Self::Value>
Scynchronously reading a value of the pattern from reader
.
Example
use handy_io::io::ReadFrom; use handy_io::pattern::{Pattern, Endian}; use handy_io::pattern::read::{U8, U16}; let pattern = (U8, U16.be()); assert_eq!(pattern.sync_read_from(&mut &[1, 0, 2][..]).unwrap(), (1, 2));
fn boxed(self) -> BoxReadFrom<R, 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<R: Read, B: AsMut<[u8]>> ReadFrom<R> for Buf<B>
impl<R: Read> ReadFrom<R> for Vec<u8>
impl<R: Read, B: AsMut<[u8]>> ReadFrom<R> for Window<B>
impl<R: Read, B: AsMut<[u8]>> ReadFrom<R> for PartialBuf<B>
impl<R: Read> ReadFrom<R> for String
impl<R: Read> ReadFrom<R> for U8
impl<R: Read> ReadFrom<R> for I8
impl<R: Read> ReadFrom<R> for U16
impl<R: Read> ReadFrom<R> for BE<U16>
impl<R: Read> ReadFrom<R> for LE<U16>
impl<R: Read> ReadFrom<R> for I16
impl<R: Read> ReadFrom<R> for BE<I16>
impl<R: Read> ReadFrom<R> for LE<I16>
impl<R: Read> ReadFrom<R> for U24
impl<R: Read> ReadFrom<R> for BE<U24>
impl<R: Read> ReadFrom<R> for LE<U24>
impl<R: Read> ReadFrom<R> for I24
impl<R: Read> ReadFrom<R> for BE<I24>
impl<R: Read> ReadFrom<R> for LE<I24>
impl<R: Read> ReadFrom<R> for U32
impl<R: Read> ReadFrom<R> for BE<U32>
impl<R: Read> ReadFrom<R> for LE<U32>
impl<R: Read> ReadFrom<R> for I32
impl<R: Read> ReadFrom<R> for BE<I32>
impl<R: Read> ReadFrom<R> for LE<I32>
impl<R: Read> ReadFrom<R> for U40
impl<R: Read> ReadFrom<R> for BE<U40>
impl<R: Read> ReadFrom<R> for LE<U40>
impl<R: Read> ReadFrom<R> for I40
impl<R: Read> ReadFrom<R> for BE<I40>
impl<R: Read> ReadFrom<R> for LE<I40>
impl<R: Read> ReadFrom<R> for U48
impl<R: Read> ReadFrom<R> for BE<U48>
impl<R: Read> ReadFrom<R> for LE<U48>
impl<R: Read> ReadFrom<R> for I48
impl<R: Read> ReadFrom<R> for BE<I48>
impl<R: Read> ReadFrom<R> for LE<I48>
impl<R: Read> ReadFrom<R> for U56
impl<R: Read> ReadFrom<R> for BE<U56>
impl<R: Read> ReadFrom<R> for LE<U56>
impl<R: Read> ReadFrom<R> for I56
impl<R: Read> ReadFrom<R> for BE<I56>
impl<R: Read> ReadFrom<R> for LE<I56>
impl<R: Read> ReadFrom<R> for U64
impl<R: Read> ReadFrom<R> for BE<U64>
impl<R: Read> ReadFrom<R> for LE<U64>
impl<R: Read> ReadFrom<R> for I64
impl<R: Read> ReadFrom<R> for BE<I64>
impl<R: Read> ReadFrom<R> for LE<I64>
impl<R: Read> ReadFrom<R> for F32
impl<R: Read> ReadFrom<R> for BE<F32>
impl<R: Read> ReadFrom<R> for LE<F32>
impl<R: Read> ReadFrom<R> for F64
impl<R: Read> ReadFrom<R> for BE<F64>
impl<R: Read> ReadFrom<R> for LE<F64>
impl<R: Read> ReadFrom<R> for Eos
impl<R: Read, F, T> ReadFrom<R> for Until<F, T> where
F: Fn(&[u8], bool) -> Result<Option<T>>,impl<R: Read, P0, P1, F> ReadFrom<R> for Then<P0, F> where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
F: FnOnce(Result<P0::Value>) -> P1,impl<R: Read, P0, P1, F> ReadFrom<R> for AndThen<P0, F> where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
F: FnOnce(P0::Value) -> P1,impl<R: Read, P0, P1, F> ReadFrom<R> for OrElse<P0, F> where
P0: ReadFrom<R>,
P1: ReadFrom<R, Value = P0::Value>,
F: FnOnce(Error) -> P1,impl<R: Read, P, F, T> ReadFrom<R> for Map<P, F> where
P: ReadFrom<R>,
F: FnOnce(P::Value) -> T,impl<R: Read, P0, P1> ReadFrom<R> for Chain<P0, P1> where
P0: ReadFrom<R>,
P1: ReadFrom<R>,impl<R: Read, I, F, T> ReadFrom<R> for IterFold<I, F, T> where
I: Iterator,
I::Item: ReadFrom<R>,
F: Fn(T, <I::Item as Pattern>::Value) -> T,impl<R: Read, I> ReadFrom<R> for Iter<I> where
I: Iterator,
I::Item: ReadFrom<R>,impl<R: Read, P> ReadFrom<R> for Option<P> where
P: ReadFrom<R>,impl<R: Read, T> ReadFrom<R> for Result<T>
impl<R: Read> ReadFrom<R> for ()
impl<R: Read, P0, P1> ReadFrom<R> for (P0, P1) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,impl<R: Read, P0, P1, P2> ReadFrom<R> for (P0, P1, P2) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3> ReadFrom<R> for (P0, P1, P2, P3) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3, P4> ReadFrom<R> for (P0, P1, P2, P3, P4) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,
P4: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3, P4, P5> ReadFrom<R> for (P0, P1, P2, P3, P4, P5) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,
P4: ReadFrom<R>,
P5: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3, P4, P5, P6> ReadFrom<R> for (P0, P1, P2, P3, P4, P5, P6) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,
P4: ReadFrom<R>,
P5: ReadFrom<R>,
P6: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3, P4, P5, P6, P7> ReadFrom<R> for (P0, P1, P2, P3, P4, P5, P6, P7) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,
P4: ReadFrom<R>,
P5: ReadFrom<R>,
P6: ReadFrom<R>,
P7: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3, P4, P5, P6, P7, P8> ReadFrom<R> for (P0, P1, P2, P3, P4, P5, P6, P7, P8) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,
P4: ReadFrom<R>,
P5: ReadFrom<R>,
P6: ReadFrom<R>,
P7: ReadFrom<R>,
P8: ReadFrom<R>,impl<R: Read, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> ReadFrom<R> for (P0, P1, P2, P3, P4, P5, P6, P7, P8, P9) where
P0: ReadFrom<R>,
P1: ReadFrom<R>,
P2: ReadFrom<R>,
P3: ReadFrom<R>,
P4: ReadFrom<R>,
P5: ReadFrom<R>,
P6: ReadFrom<R>,
P7: ReadFrom<R>,
P8: ReadFrom<R>,
P9: ReadFrom<R>,impl<R: Read, A, B, C, D, E, F, G, H> ReadFrom<R> for Branch<A, B, C, D, E, F, G, H> where
A: ReadFrom<R>,
B: ReadFrom<R, Value = A::Value>,
C: ReadFrom<R, Value = A::Value>,
D: ReadFrom<R, Value = A::Value>,
E: ReadFrom<R, Value = A::Value>,
F: ReadFrom<R, Value = A::Value>,
G: ReadFrom<R, Value = A::Value>,
H: ReadFrom<R, Value = A::Value>,impl<R: Read, T> ReadFrom<R> for BoxReadFrom<R, T>