pub struct Matcher<I, A> { /* private fields */ }Expand description
Ordered pattern matcher: first matching arm wins.
Implementations§
Source§impl<I: 'static, A: 'static> Matcher<I, A>
impl<I: 'static, A: 'static> Matcher<I, A>
Sourcepub fn when(
self,
pred: Predicate<I>,
handler: impl Fn(I) -> A + Send + Sync + 'static,
) -> Self
pub fn when( self, pred: Predicate<I>, handler: impl Fn(I) -> A + Send + Sync + 'static, ) -> Self
Add a predicate arm evaluated before later arms.
Sourcepub fn tag(
self,
expected: impl Into<String>,
handler: impl Fn(I) -> A + Send + Sync + 'static,
) -> Selfwhere
I: HasTag,
pub fn tag(
self,
expected: impl Into<String>,
handler: impl Fn(I) -> A + Send + Sync + 'static,
) -> Selfwhere
I: HasTag,
Add a tag arm: matches when HasTag::tag equals expected (string equality).
Sourcepub fn or_else(self, handler: impl Fn(I) -> A + Send + Sync + 'static) -> Self
pub fn or_else(self, handler: impl Fn(I) -> A + Send + Sync + 'static) -> Self
Fallback when no arm matches (used by Matcher::exhaustive only).
Sourcepub fn run_exhaustive(self, input: I) -> A
pub fn run_exhaustive(self, input: I) -> A
Run this matcher once. Unlike Self::exhaustive, does not require I: Send (no shareable closure).
Sourcepub fn exhaustive(self) -> impl Fn(I) -> Awhere
I: 'static,
A: 'static,
pub fn exhaustive(self) -> impl Fn(I) -> Awhere
I: 'static,
A: 'static,
Fn(I) -> A that panics when nothing matches and no Matcher::or_else was set.
The closure is only Send + Sync when I: Send (it captures Arc<Matcher<…>> and may be
invoked with I across threads).
Trait Implementations§
Auto Trait Implementations§
impl<I, A> Freeze for Matcher<I, A>
impl<I, A> !RefUnwindSafe for Matcher<I, A>
impl<I, A> Send for Matcher<I, A>
impl<I, A> Sync for Matcher<I, A>
impl<I, A> Unpin for Matcher<I, A>
impl<I, A> UnsafeUnpin for Matcher<I, A>
impl<I, A> !UnwindSafe for Matcher<I, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more