Struct DynBoxSliceCopied

Source
pub struct DynBoxSliceCopied<Output, T>
where Output: Tuple, T: Copy,
{ /* private fields */ }
Expand description

A Box<dyn Parser> wrapper for iterators of std::iter::Copied<std::slice::Iter>.

This can take any parser with Output of Output.

Once you wrap the parser with this, you can only use input iterator of std::iter::Copied<std::slice::Iter>.

Default is implemented, with always-panic-parser

use rusty_parser as rp;
use rp::IntoParser;

let mut parser = rp::DynBoxSliceCopied::<(i32,), i32>::default();
// #[should_panic]
// let res = rp::parse(&parser, (&[1,2,3]).iter().copied());

parser.assign( 0..=9 );
let res = rp::parse(&parser, (&[1,2,3,4,5,6]).iter().copied());
assert_eq!( res.output.unwrap(), (1,) );

Implementations§

Source§

impl<Output, T> DynBoxSliceCopied<Output, T>
where Output: Tuple, T: Copy,

Source

pub fn new<ParserType: IntoParser>(parser: ParserType) -> Self
where ParserType::Into: for<'a> Parser<Copied<Iter<'a, T>>, Output = Output> + 'static,

Source

pub fn assign<ParserType: IntoParser>(&mut self, parser: ParserType)
where ParserType::Into: for<'a> Parser<Copied<Iter<'a, T>>, Output = Output> + 'static,

Trait Implementations§

Source§

impl<Output: Tuple + 'static, T: Copy + 'static> Default for DynBoxSliceCopied<Output, T>

default to dummy parser that always panic

Source§

fn default() -> Self

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

impl<Output, T> Deref for DynBoxSliceCopied<Output, T>
where Output: Tuple, T: Copy,

Source§

type Target = Box<dyn for<'a> Parser<Copied<Iter<'a, T>>, Output = Output>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Output, T> DerefMut for DynBoxSliceCopied<Output, T>
where Output: Tuple, T: Copy,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Output, T> IntoParser for DynBoxSliceCopied<Output, T>
where Output: Tuple, T: Copy,

Source§

type Into = DynBoxSliceCopied<Output, T>

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 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<'a, Output, T> Parser<Copied<Iter<'a, T>>> for DynBoxSliceCopied<Output, T>
where Output: Tuple, T: Copy,

Source§

type Output = Output

Source§

fn parse( &self, it: Copied<Iter<'a, T>>, ) -> ParseResult<Self::Output, Copied<Iter<'a, T>>>

Source§

fn match_pattern( &self, it: Copied<Iter<'a, T>>, ) -> ParseResult<(), Copied<Iter<'a, T>>>

Auto Trait Implementations§

§

impl<Output, T> Freeze for DynBoxSliceCopied<Output, T>

§

impl<Output, T> !RefUnwindSafe for DynBoxSliceCopied<Output, T>

§

impl<Output, T> !Send for DynBoxSliceCopied<Output, T>

§

impl<Output, T> !Sync for DynBoxSliceCopied<Output, T>

§

impl<Output, T> Unpin for DynBoxSliceCopied<Output, T>

§

impl<Output, T> !UnwindSafe for DynBoxSliceCopied<Output, T>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.