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§
Provided Methods§
Sourcefn then<F, P, E>(self, f: F) -> Then<Self, F, E>
fn then<F, P, E>(self, f: F) -> Then<Self, F, E>
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.
Sourcefn and_then<F, P>(self, f: F) -> AndThen<Self, F>
fn and_then<F, P>(self, f: F) -> AndThen<Self, F>
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.
Sourcefn or_else<F, P, E>(self, f: F) -> OrElse<Self, F, E>where
F: FnOnce(E) -> P,
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.
Sourcefn or<P>(self, other: P) -> Or<Self, P>
fn or<P>(self, other: P) -> Or<Self, P>
Takes a pattern other which will be used if the evaluation of self is failed.
Sourcefn map<F, T>(self, f: F) -> Map<Self, F>
fn map<F, T>(self, f: F) -> Map<Self, F>
Takes a closure which maps a value to another value, and
creates a pattern which calls that closure on the evaluated value of self.
Sourcefn chain<P>(self, other: P) -> Chain<Self, P>where
P: Pattern,
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.
Sourcefn repeat(self) -> Repeat<Self>where
Self: Clone,
fn repeat(self) -> Repeat<Self>where
Self: Clone,
Creates Repeat pattern to represent an infinite stream of this pattern.
Sourcefn expect_eq(self, expected_value: Self::Value) -> Expect<Self>
fn expect_eq(self, expected_value: Self::Value) -> Expect<Self>
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());Sourcefn boxed<M: Matcher>(self) -> BoxPattern<M, Self::Value>
fn boxed<M: Matcher>(self) -> BoxPattern<M, Self::Value>
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.