pub struct MapParser<T, M> { /* private fields */ }Expand description
Maps the result of a parser to a new value
§Example
use microparsec::{MapParser, IntegerParser, SequenceParser, StringParser, ParserRc, ContextParserT, StringParserT, parsers};
let hello_parser = StringParser::new("Hello");
let space_parser = StringParser::new(" ");
let world_parser = StringParser::new("World");
let hello_world_parser = SequenceParser::new(parsers!(hello_parser, space_parser, world_parser));
let res = MapParser::new(ParserRc::new(hello_world_parser),
|res| Ok(res.val.join("")))
.parse("Hello World");
assert_eq!(res.unwrap().val, "Hello World");
let res = MapParser::new(ParserRc::new(IntegerParser::new()),
|res| Ok(res.val.parse::<u32>().unwrap()))
.parse("234");
assert_eq!(res.unwrap().val, 234);Implementations§
Trait Implementations§
Source§impl<T, M> ContextParserT<M> for MapParser<T, M>
impl<T, M> ContextParserT<M> for MapParser<T, M>
Source§fn get_generic_error_message(&self) -> String
fn get_generic_error_message(&self) -> String
Returns a generic error message of the parser that is configured at initialization and
independent of the runtime result of the attempted parse
Source§fn get_parser_type(&self) -> ParserType
fn get_parser_type(&self) -> ParserType
Returns the
ParserType of the parser (used for stack traces and error messages)Auto Trait Implementations§
impl<T, M> !RefUnwindSafe for MapParser<T, M>
impl<T, M> !Send for MapParser<T, M>
impl<T, M> !Sync for MapParser<T, M>
impl<T, M> !UnwindSafe for MapParser<T, M>
impl<T, M> Freeze for MapParser<T, M>
impl<T, M> Unpin for MapParser<T, M>
impl<T, M> UnsafeUnpin for MapParser<T, M>
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