DictBTree

Struct DictBTree 

Source
pub struct DictBTree<Output, CharType>
where Output: Clone + Tuple, CharType: Ord,
{ /* 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§

Source§

impl<Output, CharType> DictBTreeParser<Output, CharType>
where Output: Clone + Tuple, CharType: Ord,

Source

pub fn new() -> Self

Source

pub fn insert<CharIter>( &mut self, key: CharIter, output: Output, ) -> Option<Output>
where CharIter: Iterator<Item = CharType>,

Trait Implementations§

Source§

impl<Output, CharType> Clone for DictBTreeParser<Output, CharType>
where Output: Clone + Tuple + Clone, CharType: Ord + Clone,

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<Output, CharType> Debug for DictBTreeParser<Output, CharType>
where Output: Clone + Tuple + Debug, CharType: Ord + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Output, CharType> Default for DictBTreeParser<Output, CharType>
where Output: Clone + Tuple + Default, CharType: Ord + Default,

Source§

fn default() -> DictBTreeParser<Output, CharType>

Returns the “default value” for a type. Read more
Source§

impl<Output, CharType> IntoParser for DictBTreeParser<Output, CharType>
where Output: Clone + Tuple, CharType: Ord,

Source§

type Into = DictBTreeParser<Output, CharType>

Target Parser type
Source§

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,

concatenate two parser Read more
Source§

fn repeat<RangeTypeIncludeInteger>( self, range: RangeTypeIncludeInteger, ) -> RepeatParser<Self::Into, RangeTypeIncludeInteger::Into>
where Self: Sized, RangeTypeIncludeInteger: ToCopyable, RangeTypeIncludeInteger::Into: RangeBound<usize>,

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,

or combinator for two parsers Read more
Source§

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,

Change Parser’s Output to (). This internally call crate::match_pattern() instead of crate::parse() Read more
Source§

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,

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,

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,

Match for parser1 but not parser2. Read more
Source§

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>
where Self: Sized, Self::Into: for<'a> Parser<Chars<'a>>,

Returns String of parsed input. Only works for parsing with std::str::Chars. Read more
Source§

fn vec<T>(self) -> VecParser<Self::Into>
where Self: Sized, Self::Into: for<'a> Parser<Cloned<Iter<'a, T>>>,

Returns Vec\<T\> of parsed input. Only works for parsing with ExactSizeIterator. Read more
Source§

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,

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,

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>
where Self: Sized, Init: Clone,

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>
where Self: Sized, Init: Clone,

Reduce the output of the parser with the given reducer. Read more
Source§

fn inspect<ClosureType>( self, closure: ClosureType, ) -> InspectParser<Self::Into, ClosureType>
where Self: Sized, ClosureType: Fn(),

This does what std::iter::Inspect do. The closure will be called before parsing, regardless of the success or failure of the parser. 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,

Source§

type Output = Output

Source§

fn parse(&self, it: It) -> ParseResult<Self::Output, It>

Source§

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>
where Output: Send, CharType: Send,

§

impl<Output, CharType> Sync for DictBTreeParser<Output, CharType>
where Output: Sync, CharType: Sync,

§

impl<Output, CharType> Unpin for DictBTreeParser<Output, CharType>
where Output: Unpin,

§

impl<Output, CharType> UnwindSafe for DictBTreeParser<Output, CharType>
where CharType: RefUnwindSafe, Output: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.