pub struct DictBTree<Output, CharType>{ /* private fields */ }Expand description
Dictionary using trie, implementation uses std::collections::BTreeMap; O(log(N)) search.
This will match as long as possible, regardless of the order of insertion.
Output: Output you inserted
§Example
use rusty_parser as rp;
use rp::IntoParser;
let mut parser = rp::DictBTree::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 DictBTreeParser<Output, CharType>
impl<Output, CharType> Clone for DictBTreeParser<Output, CharType>
Source§fn clone(&self) -> DictBTreeParser<Output, CharType>
fn clone(&self) -> DictBTreeParser<Output, CharType>
Returns a duplicate 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 DictBTreeParser<Output, CharType>
impl<Output, CharType> Debug for DictBTreeParser<Output, CharType>
Source§impl<Output, CharType> Default for DictBTreeParser<Output, CharType>
impl<Output, CharType> Default for DictBTreeParser<Output, CharType>
Source§fn default() -> DictBTreeParser<Output, CharType>
fn default() -> DictBTreeParser<Output, CharType>
Returns the “default value” for a type. Read more
Source§impl<Output, CharType> IntoParser for DictBTreeParser<Output, CharType>
impl<Output, CharType> IntoParser for DictBTreeParser<Output, CharType>
Source§type Into = DictBTreeParser<Output, CharType>
type Into = DictBTreeParser<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>(
self,
callback: ClosureType,
) -> MapParser<Self::Into, ClosureType>where
Self: Sized,
fn map<ClosureType>(
self,
callback: ClosureType,
) -> MapParser<Self::Into, ClosureType>where
Self: Sized,
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 crate::match_pattern() instead of crate::parse() Read moreSource§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>(
self,
output: Output,
) -> OptionalOrParser<Self::Into, Output>where
Self: Sized,
fn optional_or<Output: Clone>(
self,
output: Output,
) -> OptionalOrParser<Self::Into, Output>where
Self: Sized,
This parser always success whether the input is matched or not.
If it failed, the given value will be returned. Read more
Source§fn or_else<Closure>(
self,
closure: Closure,
) -> OptionalOrElseParser<Self::Into, Closure>where
Self: Sized,
fn or_else<Closure>(
self,
closure: Closure,
) -> OptionalOrElseParser<Self::Into, Closure>where
Self: Sized,
This parser always success whether the input is matched or not.
If it failed, the given closure will be evaluated and returned. Read more
Source§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 but not parser2. Read more
Source§fn output<Output: Clone>(
self,
output: Output,
) -> OutputParser<Self::Into, Output>where
Self: Sized,
fn output<Output: Clone>(
self,
output: Output,
) -> OutputParser<Self::Into, Output>where
Self: Sized,
Change Parser’s Output to (output,). Read more
Source§fn string(self) -> StringParser<Self::Into>
fn string(self) -> StringParser<Self::Into>
Returns String of parsed input.
Only works for parsing with
std::str::Chars. Read moreSource§fn not_consume(self) -> NotConsumeParser<Self::Into>where
Self: Sized,
fn not_consume(self) -> NotConsumeParser<Self::Into>where
Self: Sized,
Parser will not consume the input iterator.
It still matches and return the output. Read more
Source§fn reduce_left<RhsParser, Reducer>(
self,
rhs: RhsParser,
reducer: Reducer,
) -> ReduceLeftParser<Self::Into, RhsParser::Into, Reducer>where
Self: Sized,
RhsParser: IntoParser,
fn reduce_left<RhsParser, Reducer>(
self,
rhs: RhsParser,
reducer: Reducer,
) -> ReduceLeftParser<Self::Into, RhsParser::Into, Reducer>where
Self: Sized,
RhsParser: IntoParser,
Reduce the output of the parser with the given reducer. Read more
Source§fn reduce_right<LhsParser, Reducer>(
self,
lhs: LhsParser,
reducer: Reducer,
) -> ReduceRightParser<LhsParser::Into, Self::Into, Reducer>where
Self: Sized,
LhsParser: IntoParser,
fn reduce_right<LhsParser, Reducer>(
self,
lhs: LhsParser,
reducer: Reducer,
) -> ReduceRightParser<LhsParser::Into, Self::Into, Reducer>where
Self: Sized,
LhsParser: IntoParser,
Reduce the output of the parser with the given reducer. Read more
Source§fn reduce_with<Init, Reducer>(
self,
init: Init,
reducer: Reducer,
) -> ReduceInitParser<Self::Into, Init, Reducer>
fn reduce_with<Init, Reducer>( self, init: Init, reducer: Reducer, ) -> ReduceInitParser<Self::Into, Init, Reducer>
Reduce the output of the parser with the given reducer. Read more
Source§fn reduce_right_with<Init, Reducer>(
self,
init: Init,
reducer: Reducer,
) -> ReduceRightInitParser<Self::Into, Init, Reducer>
fn reduce_right_with<Init, Reducer>( self, init: Init, reducer: Reducer, ) -> ReduceRightInitParser<Self::Into, Init, Reducer>
Reduce the output of the parser with the given reducer. Read more
Source§impl<Output, CharType, It> Parser<It> for DictBTreeParser<Output, CharType>where
Output: Clone + Tuple,
CharType: Ord,
It: InputIteratorTrait + Iterator<Item = CharType> + Clone,
impl<Output, CharType, It> Parser<It> for DictBTreeParser<Output, CharType>where
Output: Clone + Tuple,
CharType: Ord,
It: InputIteratorTrait + Iterator<Item = CharType> + Clone,
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 DictBTreeParser<Output, CharType>where
Output: Freeze,
impl<Output, CharType> RefUnwindSafe for DictBTreeParser<Output, CharType>where
Output: RefUnwindSafe,
CharType: RefUnwindSafe,
impl<Output, CharType> Send for DictBTreeParser<Output, CharType>
impl<Output, CharType> Sync for DictBTreeParser<Output, CharType>
impl<Output, CharType> Unpin for DictBTreeParser<Output, CharType>where
Output: Unpin,
impl<Output, CharType> UnwindSafe for DictBTreeParser<Output, CharType>
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