Skip to main content

Range

Struct Range 

Source
pub struct Range<T> {
    pub start: usize,
    pub end: usize,
    /* private fields */
}
Expand description

Wrapper that records the [start, end) input span its ranged value was parsed from.

Fields§

§start: usize

Byte offset where the ranged value started matching.

§end: usize

Byte offset just past where the ranged value finished matching.

Implementations§

Source§

impl<T> Range<T>

Source

pub fn new(start: usize, ranged: T, end: usize) -> Self

Construct a Range from an already-known span.

Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Range<U>

Apply f to the ranged value, keeping the same span.

Source

pub fn as_ref(&self) -> Range<&T>

Borrow the ranged value, keeping the same span.

Source§

impl<T> Range<Option<T>>

Source

pub fn transpose(self) -> Option<Range<T>>

Swap Range<Option<T>> for Option<Range<T>>.

Source§

impl<T, E> Range<Result<T, E>>

Source

pub fn transpose(self) -> Result<Range<T>, E>

Swap Range<Result<T, E>> for Result<Range<T>, E>.

Trait Implementations§

Source§

impl<T: Clone> Clone for Range<T>

Source§

fn clone(&self) -> Range<T>

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<T: Debug> Debug for Range<T>

Source§

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

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

impl<T> Deref for Range<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: Eq> Eq for Range<T>

Source§

impl<T: Grammar> Grammar for Range<T>

Source§

type First = <T as Grammar>::First

The set of bytes (and whether empty input is valid) this grammar could start with — used to fast-path-reject an alternative before actually trying to parse it. A manual impl Grammar picks its First one of three ways, in order of preference: Read more
Source§

fn parse_at(input: &str, pos: usize, state: State<'_>) -> Option<(Self, usize)>

Attempt to parse Self starting at pos, returning the value and the position just past it, or None on failure.
Source§

fn scan_at(input: &str, pos: usize, state: State<'_>) -> Option<usize>

Like parse_at, but only checks well-formedness and returns the end position.
Source§

fn print_to(&self, buf: &mut String)

Serialize self back to text, appending to buf.
Source§

fn to_bnf() -> Expr

Describe this grammar as a BNF/EBNF expression, for use in a referencing rule’s own definition.
Source§

fn fail_at(pos: usize, state: State<'_>) -> bool

Record what this grammar would have expected at pos, without attempting to actually parse — used when a caller already knows (e.g. via First) that this alternative cannot match here, but still wants it traced. Read more
Source§

fn parse(input: &str) -> Result<Self, Error>

Parse the entire input as Self, failing if any input is left unconsumed.
Source§

fn parse_prefix(input: &str) -> Result<(Self, usize), Error>

Like parse, but doesn’t require consuming all of input — returns the byte position just past the match, leaving any remaining input unexamined.
Source§

fn scan(input: &str) -> Result<(), Error>

Like parse, but only checks that input is well-formed and discards the parsed value.
Source§

fn scan_prefix(input: &str) -> Result<usize, Error>

Like scan, but doesn’t require consuming all of input — returns the byte position just past the match, leaving any remaining input unexamined.
Source§

fn print(&self) -> String

Serialize self to a new String; see print_to.
Source§

impl<T> IntoInner<T> for Range<T>

Source§

fn into_inner(self) -> T

Consume self, discarding whatever structure wrapped T.
Source§

impl<T: PartialEq> PartialEq for Range<T>

Source§

fn eq(&self, other: &Range<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Range<T>

Auto Trait Implementations§

§

impl<T> Freeze for Range<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Range<T>
where T: RefUnwindSafe,

§

impl<T> Send for Range<T>
where T: Send,

§

impl<T> Sync for Range<T>
where T: Sync,

§

impl<T> Unpin for Range<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Range<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Range<T>
where T: 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.