OrExt

Trait OrExt 

Source
pub trait OrExt<I, O, E, R> {
    // Provided methods
    fn or<P>(self, p: P) -> Or<Self, P>
       where Self: Sized,
             I: Clone,
             P: Pipe<I, O, E, R> { ... }
    fn or_self<O2, P>(self, p: P) -> OrSelf<O, O2, Self, P>
       where Self: Sized,
             O: Unpack,
             I: Clone,
             P: Pipe<I, O2, E, R> { ... }
    fn or_other<O2, P>(self, p: P) -> OrOther<O, O2, Self, P>
       where Self: Sized,
             I: Clone,
             O2: Unpack,
             P: Pipe<I, O2, E, R> { ... }
}
Expand description

Or combinator

Provided Methods§

Source

fn or<P>(self, p: P) -> Or<Self, P>
where Self: Sized, I: Clone, P: Pipe<I, O, E, R>,

Apply the second Pipe if the first fails

Example:

assert_eq!(tag::<Error, _, _>("foo").or(tag("bar")).apply("foo"), Ok(("", ("foo",))));

assert_eq!(tag::<Error, _, _>("foo").or(tag("boo")).apply("boo"), Ok(("", ("boo",))));

assert_eq!(
    tag::<Error, _, _>("foo").or(tag("boo")).apply("something"),
    Err(FatalError::Error(Error::Tag(TagStrError("boo".into(), "som".into()))))
);
Source

fn or_self<O2, P>(self, p: P) -> OrSelf<O, O2, Self, P>
where Self: Sized, O: Unpack, I: Clone, P: Pipe<I, O2, E, R>,

Apply the second Pipe if the first fails discarding the output of the second pipe

Example:

assert_eq!(
    tag::<Error, _, _>("foo").or_self(tag("bar")).apply("foo"),
    Ok(("", (Some("foo"),)))
);

assert_eq!(
    tag::<Error, _, _>("foo").or_self(tag("boo")).apply("boo"),
    Ok(("", (None,)))
);

assert_eq!(
    tag::<Error, _, _>("foo").or_self(tag("boo")).apply("something"),
    Err(FatalError::Error(Error::Tag(TagStrError("boo".into(), "som".into()))))
);
Source

fn or_other<O2, P>(self, p: P) -> OrOther<O, O2, Self, P>
where Self: Sized, I: Clone, O2: Unpack, P: Pipe<I, O2, E, R>,

Apply the second Pipe if the first fails discarding the output of the first pipe

Example:

assert_eq!(
    tag::<Error, _, _>("foo").or_other(tag("bar")).apply("foo"),
    Ok(("", (None,)))
);

assert_eq!(
    tag::<Error, _, _>("foo").or_other(tag("boo")).apply("boo"),
    Ok(("", (Some("boo"),)))
);

assert_eq!(
    tag::<Error, _, _>("foo").or_other(tag("boo")).apply("something"),
    Err(FatalError::Error(Error::Tag(TagStrError("boo".into(), "som".into()))))
);

Implementors§

Source§

impl<I, O, E, R, P> OrExt<I, O, E, R> for P
where P: Pipe<I, O, E, R>,