Trait Pattern

Source
pub trait Pattern: Sized {
    type Value;

    // Provided methods
    fn then<F, P, E>(self, f: F) -> Then<Self, F, E>
       where F: FnOnce(Result<Self::Value, E>) -> P { ... }
    fn and_then<F, P>(self, f: F) -> AndThen<Self, F>
       where F: FnOnce(Self::Value) -> P { ... }
    fn or_else<F, P, E>(self, f: F) -> OrElse<Self, F, E>
       where F: FnOnce(E) -> P { ... }
    fn or<P>(self, other: P) -> Or<Self, P>
       where P: Pattern<Value = Self::Value> { ... }
    fn map<F, T>(self, f: F) -> Map<Self, F>
       where F: FnOnce(Self::Value) -> T { ... }
    fn chain<P>(self, other: P) -> Chain<Self, P>
       where P: Pattern { ... }
    fn repeat(self) -> Repeat<Self>
       where Self: Clone { ... }
    fn expect_eq(self, expected_value: Self::Value) -> Expect<Self>
       where Self::Value: PartialEq { ... }
    fn boxed<M: Matcher>(self) -> BoxPattern<M, Self::Value>
       where Self: AsyncMatch<M> + 'static,
             Self::Future: Send + 'static { ... }
}
Expand description

Pattern.

Required Associated Types§

Source

type Value

The value type associated to the pattern.

Provided Methods§

Source

fn then<F, P, E>(self, f: F) -> Then<Self, F, E>
where F: FnOnce(Result<Self::Value, E>) -> P,

Takes a closure which maps a Result<Self::Value> to a pattern, and creates a pattern which calls that closure on the evaluation result of self.

Source

fn and_then<F, P>(self, f: F) -> AndThen<Self, F>
where F: FnOnce(Self::Value) -> P,

Takes a closure which maps a value to a pattern, and creates a pattern which calls that closure if the evaluation of self was succeeded.

Source

fn or_else<F, P, E>(self, f: F) -> OrElse<Self, F, E>
where F: FnOnce(E) -> P,

Takes a closure which maps an error to a pattern, and creates a pattern which calls that closure if the evaluation of self failed.

Source

fn or<P>(self, other: P) -> Or<Self, P>
where P: Pattern<Value = Self::Value>,

Takes a pattern other which will be used if the evaluation of self is failed.

Source

fn map<F, T>(self, f: F) -> Map<Self, F>
where F: FnOnce(Self::Value) -> T,

Takes a closure which maps a value to another value, and creates a pattern which calls that closure on the evaluated value of self.

Source

fn chain<P>(self, other: P) -> Chain<Self, P>
where P: Pattern,

Takes two patterns and creates a new pattern over both in sequence.

In generally, using the tuple pattern (self, P) is more convenient way to achieve the same effect.

Source

fn repeat(self) -> Repeat<Self>
where Self: Clone,

Creates Repeat pattern to represent an infinite stream of this pattern.

Source

fn expect_eq(self, expected_value: Self::Value) -> Expect<Self>
where Self::Value: PartialEq,

Takes an expected value and creates a pattern which performs a pattern matching and validates that the matched value is equal to the expected one.

§Examples
use handy_async::pattern::Pattern;
use handy_async::pattern::read::U8;
use handy_async::io::ReadFrom;

assert!(U8.expect_eq(b'H').sync_read_from(&b"Hello"[..]).is_ok());
assert!(U8.expect_eq(b'A').sync_read_from(&b"Hello"[..]).is_err());
Source

fn boxed<M: Matcher>(self) -> BoxPattern<M, Self::Value>
where Self: AsyncMatch<M> + 'static, Self::Future: Send + 'static,

Returnes a boxed pattern to match with a matcher M.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Pattern for i8

Source§

impl Pattern for i16

Source§

impl Pattern for i32

Source§

impl Pattern for i64

Source§

impl Pattern for u8

Source§

impl Pattern for u16

Source§

impl Pattern for u32

Source§

impl Pattern for u64

Source§

impl Pattern for ()

Source§

impl Pattern for String

Source§

impl Pattern for Vec<u8>

Source§

impl<P0: Pattern, P1: Pattern> Pattern for (P0, P1)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern> Pattern for (P0, P1, P2)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern> Pattern for (P0, P1, P2, P3)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern, P4: Pattern> Pattern for (P0, P1, P2, P3, P4)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value, <P4 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern, P4: Pattern, P5: Pattern> Pattern for (P0, P1, P2, P3, P4, P5)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value, <P4 as Pattern>::Value, <P5 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern, P4: Pattern, P5: Pattern, P6: Pattern> Pattern for (P0, P1, P2, P3, P4, P5, P6)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value, <P4 as Pattern>::Value, <P5 as Pattern>::Value, <P6 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern, P4: Pattern, P5: Pattern, P6: Pattern, P7: Pattern> Pattern for (P0, P1, P2, P3, P4, P5, P6, P7)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value, <P4 as Pattern>::Value, <P5 as Pattern>::Value, <P6 as Pattern>::Value, <P7 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern, P4: Pattern, P5: Pattern, P6: Pattern, P7: Pattern, P8: Pattern> Pattern for (P0, P1, P2, P3, P4, P5, P6, P7, P8)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value, <P4 as Pattern>::Value, <P5 as Pattern>::Value, <P6 as Pattern>::Value, <P7 as Pattern>::Value, <P8 as Pattern>::Value)

Source§

impl<P0: Pattern, P1: Pattern, P2: Pattern, P3: Pattern, P4: Pattern, P5: Pattern, P6: Pattern, P7: Pattern, P8: Pattern, P9: Pattern> Pattern for (P0, P1, P2, P3, P4, P5, P6, P7, P8, P9)

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value, <P2 as Pattern>::Value, <P3 as Pattern>::Value, <P4 as Pattern>::Value, <P5 as Pattern>::Value, <P6 as Pattern>::Value, <P7 as Pattern>::Value, <P8 as Pattern>::Value, <P9 as Pattern>::Value)

Source§

impl<T, E> Pattern for Result<T, E>

Source§

type Value = T

Implementors§

Source§

impl Pattern for All

Source§

impl Pattern for Eos

Source§

impl Pattern for F32

Source§

impl Pattern for F64

Source§

impl Pattern for I8

Source§

impl Pattern for I16

Source§

impl Pattern for handy_async::pattern::read::I24

Source§

impl Pattern for I32

Source§

impl Pattern for handy_async::pattern::read::I40

Source§

impl Pattern for handy_async::pattern::read::I48

Source§

impl Pattern for handy_async::pattern::read::I56

Source§

impl Pattern for I64

Source§

impl Pattern for Line

Source§

impl Pattern for U8

Source§

impl Pattern for U16

Source§

impl Pattern for handy_async::pattern::read::U24

Source§

impl Pattern for U32

Source§

impl Pattern for handy_async::pattern::read::U40

Source§

impl Pattern for handy_async::pattern::read::U48

Source§

impl Pattern for handy_async::pattern::read::U56

Source§

impl Pattern for U64

Source§

impl Pattern for Flush

Source§

impl Pattern for handy_async::pattern::write::I24

Source§

impl Pattern for handy_async::pattern::write::I40

Source§

impl Pattern for handy_async::pattern::write::I48

Source§

impl Pattern for handy_async::pattern::write::I56

Source§

impl Pattern for handy_async::pattern::write::U24

Source§

impl Pattern for handy_async::pattern::write::U40

Source§

impl Pattern for handy_async::pattern::write::U48

Source§

impl Pattern for handy_async::pattern::write::U56

Source§

impl<A, B, C, D, E, F, G, H> Pattern for Branch<A, B, C, D, E, F, G, H>
where A: Pattern, B: Pattern<Value = A::Value>, C: Pattern<Value = A::Value>, D: Pattern<Value = A::Value>, E: Pattern<Value = A::Value>, F: Pattern<Value = A::Value>, G: Pattern<Value = A::Value>, H: Pattern<Value = A::Value>,

Source§

type Value = <A as Pattern>::Value

Source§

impl<B> Pattern for PartialBuf<B>

Source§

type Value = (B, usize)

Source§

impl<B> Pattern for Buf<B>

Source§

type Value = B

Source§

impl<B> Pattern for Window<B>

Source§

impl<F, T> Pattern for Until<F, T>

Source§

type Value = (Vec<u8>, T)

Source§

impl<I, P> Pattern for Iter<I>
where I: Iterator<Item = P>, P: Pattern,

Source§

impl<I, P, F, T> Pattern for IterFold<I, F, T>
where I: Iterator<Item = P>, P: Pattern, F: Fn(T, P::Value) -> T,

Source§

type Value = T

Source§

impl<M: Matcher, T> Pattern for BoxPattern<M, T>

Source§

type Value = T

Source§

impl<P0, P1> Pattern for Chain<P0, P1>
where P0: Pattern, P1: Pattern,

Source§

type Value = (<P0 as Pattern>::Value, <P1 as Pattern>::Value)

Source§

impl<P0, P1> Pattern for Or<P0, P1>
where P0: Pattern, P1: Pattern<Value = P0::Value>,

Source§

type Value = <P1 as Pattern>::Value

Source§

impl<P0, P1, F> Pattern for AndThen<P0, F>
where P0: Pattern, P1: Pattern, F: FnOnce(P0::Value) -> P1,

Source§

type Value = <P1 as Pattern>::Value

Source§

impl<P0, P1, F, E> Pattern for OrElse<P0, F, E>
where P0: Pattern, P1: Pattern<Value = P0::Value>, F: FnOnce(E) -> P1,

Source§

type Value = <P1 as Pattern>::Value

Source§

impl<P0, P1, F, E> Pattern for Then<P0, F, E>
where P0: Pattern, P1: Pattern, F: FnOnce(Result<P0::Value, E>) -> P1,

Source§

type Value = <P1 as Pattern>::Value

Source§

impl<P> Pattern for LengthPrefixedBytes<P>
where P: Pattern, P::Value: TryAsLength,

Source§

impl<P> Pattern for Utf8<P>
where P: Pattern, Vec<u8>: From<P::Value>,

Source§

impl<P> Pattern for Option<P>
where P: Pattern,

Source§

impl<P, F, T> Pattern for Map<P, F>
where P: Pattern, F: FnOnce(P::Value) -> T,

Source§

type Value = T

Source§

impl<P: Pattern> Pattern for Expect<P>

Source§

type Value = <P as Pattern>::Value

Source§

impl<T> Pattern for BE<T>
where T: Endian + Pattern,

Source§

type Value = <T as Pattern>::Value

Source§

impl<T> Pattern for LE<T>
where T: Endian + Pattern,

Source§

type Value = <T as Pattern>::Value