Skip to main content

ToParser

Struct ToParser 

Source
pub struct ToParser<Match, Output> { /* private fields */ }
Expand description

Parser produced by MatcherCombinator::to.

It runs a matcher and returns a fixed output value when the matcher succeeds. The matcher is evaluated with an empty capture result, so this is intended for ordinary matchers, not bind!/bind_span!/bind_slice! capture binders.

Implementations§

Source§

impl<Match, Output> ToParser<Match, Output>

Source

pub fn new(matcher: Match, output: Output) -> Self

Wrap matcher and return output whenever it succeeds.

Trait Implementations§

Source§

impl<Match: Clone, Output: Clone> Clone for ToParser<Match, Output>

Source§

fn clone(&self) -> ToParser<Match, Output>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Match, Output> Debug for ToParser<Match, Output>
where Match: Debug,

Source§

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

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

impl<Match, Output> ParserCombinator for ToParser<Match, Output>

Source§

fn memoized<T>(self) -> Memoized<Self, T>
where Self: Sized,

Memoize parse results of type T keyed by input position (including outputs that borrow the input).
Source§

fn recover_with<RecoveryParser>( self, recover_parser: RecoveryParser, ) -> ErrorRecovererInner<Self, RecoveryParser>
where Self: Sized,

On parse failure, run recover_matcher and yield recover_output if it matches.
Source§

fn add_error_info<Pars>( self, error_parser: Pars, ) -> ErrorContextualizer<Self, Pars>
where Self: Sized,

Available on crate feature parser-trace only.
Enrich hard failures from this parser with additional local context.
Source§

fn ignore_result(self) -> IgnoreResult<Self>
where Self: Sized,

Available on crate feature parser-trace only.
Run this parser as a matcher and discard the output.
Source§

fn map_output<MapFn>(self, map_fn: MapFn) -> OutputMapper<Self, MapFn>
where Self: Sized,

Map each successful parser output with map_fn, preserving parse behavior.
Source§

fn erase_types<'src, Inp, Out>(self) -> Erased<'src, 'src, Inp, Out>
where Self: Sized + Parser<'src, Inp, Output = Out> + 'src, Inp: Input<'src> + 'src, Out: 'src,

Erase this parser’s concrete type into a boxed trait object. Read more

Auto Trait Implementations§

§

impl<Match, Output> Freeze for ToParser<Match, Output>
where Match: Freeze, Output: Freeze,

§

impl<Match, Output> RefUnwindSafe for ToParser<Match, Output>
where Match: RefUnwindSafe, Output: RefUnwindSafe,

§

impl<Match, Output> Send for ToParser<Match, Output>
where Match: Send, Output: Send,

§

impl<Match, Output> Sync for ToParser<Match, Output>
where Match: Sync, Output: Sync,

§

impl<Match, Output> Unpin for ToParser<Match, Output>
where Match: Unpin, Output: Unpin,

§

impl<Match, Output> UnsafeUnpin for ToParser<Match, Output>
where Match: UnsafeUnpin, Output: UnsafeUnpin,

§

impl<Match, Output> UnwindSafe for ToParser<Match, Output>
where Match: 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> 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<'src, Inp, P> Parser<'src, Inp> for P
where Inp: Input<'src>, P: ParserImpl<'src, Inp> + 'src,

Source§

fn parse_whole_input( &self, input: Inp, ) -> Result<(<Self as ParserImpl<'src, Inp>>::Output, Vec<ParserError>), FurthestFailError>
where Self: Clone, Inp: Clone + 'src,

Parse all of input with the default whole-input + EOF crate::matcher::commit_matcher::commit_on wrapper (same driver as crate::parse for Inp = &'src str).
Source§

fn parse_str( &self, src: &'src str, ) -> Result<(<Self as ParserImpl<'src, &'src str>>::Output, Vec<ParserError>), FurthestFailError>
where Self: Parser<'src, &'src str> + Clone,

Like Self::parse_whole_input for string input (convenience alias).
Source§

fn parse_whole_input_with_trace( &self, input: Inp, ) -> Result<(<Self as ParserImpl<'src, Inp>>::Output, Vec<ParserError>, TraceSession), FurthestFailError>
where Self: Clone, Inp: Clone + 'src,

Available on crate feature parser-trace only.
Parse with tracing; same whole-input + EOF wrapper as Self::parse_whole_input.
Source§

fn parse_whole_input_with_trace_session( &self, input: Inp, trace_session: TraceSession, ) -> Result<(<Self as ParserImpl<'src, Inp>>::Output, Vec<ParserError>, TraceSession), FurthestFailError>
where Self: Clone, Inp: Clone + 'src,

Available on crate feature parser-trace only.
Source§

fn parse_str_with_trace( &self, src: &'src str, ) -> Result<(<Self as ParserImpl<'src, &'src str>>::Output, Vec<ParserError>, TraceSession), FurthestFailError>
where Self: Parser<'src, &'src str> + Clone,

Available on crate feature parser-trace only.
Convenience alias for Self::parse_whole_input_with_trace on string input.
Source§

fn parse_whole_input_with_trace_to_file( &self, input: Inp, trace_path: impl AsRef<Path>, format: TraceFormat, ) -> Result<(<Self as ParserImpl<'src, Inp>>::Output, Vec<ParserError>), ParseWithTraceToFileError>
where Self: Clone, Inp: Clone + 'src,

Available on crate feature parser-trace only.
Traced parse and write the session to trace_path (no source snapshot; spans are positions in input).
Source§

fn parse_str_with_trace_to_file( &self, src: &'src str, trace_path: impl AsRef<Path>, format: TraceFormat, ) -> Result<(<Self as ParserImpl<'src, &'src str>>::Output, Vec<ParserError>), ParseWithTraceToFileError>
where Self: Parser<'src, &'src str> + Clone,

Available on crate feature parser-trace only.
Like Self::parse_whole_input_with_trace_to_file, and records src as trace source text.
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.
Source§

impl<I> WithLabel for I

Source§

fn with_label<L>(self, label: L) -> Labeled<L, I>

Same as Labeled::new(label, self).
Source§

impl<I> WithTrace for I

Source§

fn trace(self) -> Traced<I>

Trace this parser or matcher using its existing label (if any).
Source§

fn trace_with_label(self, label: impl Into<String>) -> Traced<I>

Trace this parser or matcher with an explicit label.