Function combine::satisfy_map [−][src]
pub fn satisfy_map<Input, P, R>(predicate: P) -> SatisfyMap<Input, P> where
Input: Stream,
P: FnMut(Input::Token) -> Option<R>, Expand description
Parses a token and passes it to predicate. If predicate returns Some the parser succeeds
and returns the value inside the Option. If predicate returns None the parser fails
without consuming any input.
#[derive(Debug, PartialEq)] enum YesNo { Yes, No, } let mut parser = satisfy_map(|c| { match c { 'Y' => Some(YesNo::Yes), 'N' => Some(YesNo::No), _ => None, } }); assert_eq!(parser.parse("Y").map(|x| x.0), Ok(YesNo::Yes)); assert!(parser.parse("A").map(|x| x.0).is_err());