Struct rusty_parser::DictHashMap
source · pub struct DictHashMap<Output, CharType>{ /* private fields */ }Expand description
Dictionary using trie, implementation uses HashMap; O(1) search.
Output: Output you inserted
§Example
use rusty_parser as rp;
use rp::IntoParser;
let mut parser = rp::DictHashMap::new();
parser.insert("hello".chars(), (1,));
parser.insert("hello_world".chars(), (2,));
parser.insert("world".chars(), (3,));
// this will match as long as possible
let res = rp::parse(&parser, "hello_world_abcdefg".chars());
assert_eq!(res.output.unwrap(), (2,));
// 'hello_world' is parsed, so the rest is "_abcdefg"
assert_eq!(res.it.collect::<String>(), "_abcdefg");
// match 'hello' only
let res = rp::parse(&parser, "hello_wo".chars());
assert_eq!(res.output.unwrap(), (1,));Implementations§
Trait Implementations§
source§impl<Output, CharType> Clone for DictHashMapParser<Output, CharType>
impl<Output, CharType> Clone for DictHashMapParser<Output, CharType>
source§fn clone(&self) -> DictHashMapParser<Output, CharType>
fn clone(&self) -> DictHashMapParser<Output, CharType>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<Output, CharType> Debug for DictHashMapParser<Output, CharType>
impl<Output, CharType> Debug for DictHashMapParser<Output, CharType>
source§impl<Output, CharType> Default for DictHashMapParser<Output, CharType>
impl<Output, CharType> Default for DictHashMapParser<Output, CharType>
source§fn default() -> DictHashMapParser<Output, CharType>
fn default() -> DictHashMapParser<Output, CharType>
Returns the “default value” for a type. Read more
source§impl<CharType, Output> IntoParser for DictHashMapParser<Output, CharType>
impl<CharType, Output> IntoParser for DictHashMapParser<Output, CharType>
§type Into = DictHashMapParser<Output, CharType>
type Into = DictHashMapParser<Output, CharType>
Target Parser type
source§fn into_parser(self) -> Self::Into
fn into_parser(self) -> Self::Into
convert self to Parser Read more
source§fn seq<RhsParser: IntoParser>(
self,
rhs: RhsParser
) -> SeqParser<Self::Into, RhsParser::Into>where
Self: Sized,
fn seq<RhsParser: IntoParser>(
self,
rhs: RhsParser
) -> SeqParser<Self::Into, RhsParser::Into>where
Self: Sized,
concatenate two parser Read more
source§fn repeat<RangeTypeIncludeInteger>(
self,
range: RangeTypeIncludeInteger
) -> RepeatParser<Self::Into, RangeTypeIncludeInteger::Into>
fn repeat<RangeTypeIncludeInteger>( self, range: RangeTypeIncludeInteger ) -> RepeatParser<Self::Into, RangeTypeIncludeInteger::Into>
repeat parser multiple times. This tries to match as long as possible. Read more
source§fn or<RhsParser: IntoParser>(
self,
rhs: RhsParser
) -> OrParser<Self::Into, RhsParser::Into>where
Self: Sized,
fn or<RhsParser: IntoParser>(
self,
rhs: RhsParser
) -> OrParser<Self::Into, RhsParser::Into>where
Self: Sized,
or combinator for two parsers Read more
source§fn map<ClosureType, ClosureInput, ClosureOutput>(
self,
callback: ClosureType
) -> MapParser<Self::Into, ClosureType, ClosureInput, ClosureOutput>
fn map<ClosureType, ClosureInput, ClosureOutput>( self, callback: ClosureType ) -> MapParser<Self::Into, ClosureType, ClosureInput, ClosureOutput>
Map parser’s Output to new value Read more
source§fn void(self) -> VoidParser<Self::Into>where
Self: Sized,
fn void(self) -> VoidParser<Self::Into>where
Self: Sized,
Change Parser’s Output to ().
This internally call match_pattern() instead of parse() Read more
source§fn optional(self) -> OptionalParser<Self::Into>where
Self: Sized,
fn optional(self) -> OptionalParser<Self::Into>where
Self: Sized,
This parser always success whether the input is matched or not. Read more
source§fn optional_or<Output: Clone + Tuple>(
self,
output: Output
) -> OptionalOrParser<Self::Into, Output>where
Self: Sized,
fn optional_or<Output: Clone + Tuple>(
self,
output: Output
) -> OptionalOrParser<Self::Into, Output>where
Self: Sized,
This parser always success whether the input is matched or not. Read more
source§fn refcell(self) -> RefCelledParser<Self::Into>where
Self: Sized,
fn refcell(self) -> RefCelledParser<Self::Into>where
Self: Sized,
create RefCell<Parser> wrapper. Read more
source§fn box_slice<Output, T>(self) -> DynBoxSlice<Output, T>
fn box_slice<Output, T>(self) -> DynBoxSlice<Output, T>
create a Box<dyn Parser> wrapper for iterators of
std::iter::Cloned<std::slice::Iter>. Read moresource§fn not<RhsParser: IntoParser>(
self,
rhs: RhsParser
) -> NotParser<Self::Into, RhsParser::Into>where
Self: Sized,
fn not<RhsParser: IntoParser>(
self,
rhs: RhsParser
) -> NotParser<Self::Into, RhsParser::Into>where
Self: Sized,
Match for parser1 parser2, parser1 must success and parser2 must fail. Read more
source§fn output<Output: Tuple + Clone>(
self,
output: Output
) -> OutputParser<Self::Into, Output>where
Self: Sized,
fn output<Output: Tuple + Clone>(
self,
output: Output
) -> OutputParser<Self::Into, Output>where
Self: Sized,
Change Parser’s Output to output. Read more
source§impl<Output, CharType, It> Parser<It> for DictHashMapParser<Output, CharType>
impl<Output, CharType, It> Parser<It> for DictHashMapParser<Output, CharType>
type Output = Output
fn parse(&self, it: It) -> ParseResult<Self::Output, It>
fn match_pattern(&self, it: It) -> ParseResult<(), It>
Auto Trait Implementations§
impl<Output, CharType> Freeze for DictHashMapParser<Output, CharType>where
Output: Freeze,
impl<Output, CharType> RefUnwindSafe for DictHashMapParser<Output, CharType>where
Output: RefUnwindSafe,
CharType: RefUnwindSafe,
impl<Output, CharType> Send for DictHashMapParser<Output, CharType>
impl<Output, CharType> Sync for DictHashMapParser<Output, CharType>
impl<Output, CharType> Unpin for DictHashMapParser<Output, CharType>
impl<Output, CharType> UnwindSafe for DictHashMapParser<Output, CharType>where
CharType: UnwindSafe,
Output: UnwindSafe,
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