EitherExt

Trait EitherExt 

Source
pub trait EitherExt<I, O, E, R> {
    // Provided methods
    fn either<O2, P>(self, p: P) -> EitherPipe<O, O2, Self, P>
       where I: Clone,
             Self: Pipe<I, O, E, R> + Sized,
             P: Pipe<I, O2, E, R> { ... }
    fn either_full<O2, R2, P>(self, p: P) -> EitherPipeFull<O, O2, Self, P>
       where I: Clone,
             Self: Pipe<I, O, E, R> + Sized,
             P: Pipe<I, O2, E, R2> { ... }
}
Expand description

Either combinator

Combine 2 Pipes that can produce different outputs but share the same input

Provided Methods§

Source

fn either<O2, P>(self, p: P) -> EitherPipe<O, O2, Self, P>
where I: Clone, Self: Pipe<I, O, E, R> + Sized, P: Pipe<I, O2, E, R>,

Combine 2 Pipes with the same input and remaining but differents outputs

let mut p =
    tag::<Error, _, _>("a").either(digits::<Error>(1..).map1(|x: &str| x.parse().unwrap()));

assert_eq!(p.apply("a"), Ok(("", (Either::Left("a"),))));
assert_eq!(p.apply("12"), Ok(("", (Either::Right(12u32),))));
Source

fn either_full<O2, R2, P>(self, p: P) -> EitherPipeFull<O, O2, Self, P>
where I: Clone, Self: Pipe<I, O, E, R> + Sized, P: Pipe<I, O2, E, R2>,

Combine 2 Pipes with the same input and differents outputs and remaining

    str::digits, tag, AndThenExt, EitherExt, str::TagStrError, Incomplete, MapExt, Pipe,
};
let mut p = tag::<Error, _, _>("a").either_full(
    digits::<Error>(1..).map1(|x: &str| x.parse().unwrap()).ok_and_then(|_, x| Ok((0, x))),
);

assert_eq!(p.apply("a"), Ok((Either::Left(""), (Either::Left("a"),))));
assert_eq!(p.apply("12"), Ok((Either::Right(0), (Either::Right(12u32),))));

Implementors§

Source§

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