Struct rusty_parser::DictHashMap

source ·
pub struct DictHashMap<Output, CharType>
where CharType: Hash + Eq, Output: Clone + Tuple,
{ /* 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§

source§

impl<Output, CharType> DictHashMapParser<Output, CharType>
where CharType: Hash + Eq, Output: Clone + Tuple,

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 DictHashMapParser<Output, CharType>
where CharType: Hash + Eq + Clone, Output: Clone + Tuple + Clone,

source§

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)

Performs copy-assignment from source. Read more
source§

impl<Output, CharType> Debug for DictHashMapParser<Output, CharType>
where CharType: Hash + Eq + Debug, Output: Clone + Tuple + Debug,

source§

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

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

impl<Output, CharType> Default for DictHashMapParser<Output, CharType>
where CharType: Hash + Eq + Default, Output: Clone + Tuple + Default,

source§

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

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

impl<CharType, Output> IntoParser for DictHashMapParser<Output, CharType>
where CharType: Hash + Eq, Output: Clone + Tuple,

§

type Into = DictHashMapParser<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, ClosureInput, ClosureOutput>( self, callback: ClosureType ) -> MapParser<Self::Into, ClosureType, ClosureInput, ClosureOutput>
where ClosureInput: Tuple, ClosureType: Fn(ClosureInput) -> ClosureOutput, ClosureOutput: Tuple, 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 match_pattern() instead of 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 + 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,

create RefCell<Parser> wrapper. Read more
source§

fn rc(self) -> RcedParser<Self::Into>
where Self: Sized,

Create Rc<Parser> wrapper. Read more
source§

fn box_slice<Output, T>(self) -> DynBoxSlice<Output, T>
where Output: Tuple, T: Clone + Copy, Self: Sized, Self::Into: for<'a> Parser<Cloned<Iter<'a, T>>, Output = Output> + 'static,

create a Box<dyn Parser> wrapper for iterators of std::iter::Cloned<std::slice::Iter>. Read more
source§

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,

Change Parser’s Output to output. 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 std::iter::Cloned<std::slice::Iter>. Read more
source§

fn not_consume(self) -> NotConsumeParser<Self::Into>
where Self: Sized,

Parser will not consume the input iterator. It still match and return the output. Read more
source§

impl<Output, CharType, It> Parser<It> for DictHashMapParser<Output, CharType>
where It: InputIteratorTrait + Iterator<Item = CharType> + Clone, CharType: Hash + Eq, Output: Clone + Tuple,

§

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

§

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

§

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

§

impl<Output, CharType> UnwindSafe for DictHashMapParser<Output, CharType>
where CharType: UnwindSafe, Output: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.