Struct ParseableStr

Source
pub struct ParseableStr<'t, B: Backing> {
    pub position: usize,
    pub backing: &'t B,
    pub s: &'t str,
}

Fields§

§position: usize§backing: &'t B§s: &'t str

Implementations§

Source§

impl<'t, B: Backing> ParseableStr<'t, B>

Source

pub fn new(backing: &'t B) -> Self

Source

pub fn position_difference(&self, to: &Self) -> usize

Panics if to is before self.

Source

pub fn up_to(&self, to: &Self) -> Self

Panics if to is before self.

Source

pub fn eos(&self) -> ParseableStr<'t, B>

Return the end of this string, with the correct position.

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn first(&self) -> Option<char>

Source

pub fn starts_with(&self, s: &str) -> bool

You usually want drop_str instead.

Source§

impl<'t, B: Backing> ParseableStr<'t, B>

Source

pub fn parse<T: FromStr>(&self) -> Result<T, Box<FromStrError>>
where T::Err: Display,

Parse the whole string via FromStr, returning error information.

Source

pub fn opt_parse<T: FromStr>(&self) -> Option<T>

Try to parse the whole string via FromStr.

Source

pub fn skip_bytes(&self, num_bytes: usize) -> ParseableStr<'t, B>

Skip the given number of bytes from the beginning. Panics if num_bytes goes beyond the end of self, and will lead to later panics if the result is not pointing at a character boundary.

Source

pub fn split_at(&self, mid: usize) -> (ParseableStr<'t, B>, ParseableStr<'t, B>)

Split at the given number of bytes from the beginning. Panics if mid > len, or not pointing at a character boundary.

Source

pub fn trim(&self) -> ParseableStr<'t, B>

Trim whitespace from start end end.

Source

pub fn trim_start(&self) -> ParseableStr<'t, B>

Trim whitespace from the end.

Source

pub fn trim_end(&self) -> ParseableStr<'t, B>

Trim whitespace from the end.

Source

pub fn find_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>

Find the first occurrence of needle in self, return the needle and what follows.

Source

pub fn find_str_rest( &self, needle: &str, ) -> Option<(ParseableStr<'t, B>, ParseableStr<'t, B>)>

Find the first occurrence of needle in self, return the needle itself (with the position information of where it was found) and the rest after it.

Source

pub fn after_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>

Find the first occurrence of needle in self, return the rest after it.

Source

pub fn drop_str(&self, beginning: &str) -> Option<ParseableStr<'t, B>>

Expect beginning at the start of self, if so return the remainder after it.

Source

pub fn expect_str( &self, beginning: &'t str, ) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>

Same as drop_str but returns an error mentioning beginning if it doesn’t match

Source

pub fn expect_str_or_eos( &self, beginning: &'t str, ) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>

Source

pub fn expect_separator( &self, separator: &Separator, ) -> Result<ParseableStr<'t, B>, Box<ExpectedString<'t, B>>>

Source

pub fn take_until_str(&self, needle: &str) -> Option<ParseableStr<'t, B>>

Find the first occurrence of needle in self, return the part left of it.

Source

pub fn split_at_str( &self, needle: &str, ) -> Option<(ParseableStr<'t, B>, ParseableStr<'t, B>)>

Split at the first occurrence of needle, returning the parts before and after it.

Source

pub fn take_while( &self, pred: impl FnMut(char) -> bool, ) -> (ParseableStr<'t, B>, ParseableStr<'t, B>)

Take every character for which pred returns true, return the string making up those characters and the remainder.

Source

pub fn expect1_matching( &self, pred: impl FnOnce(char) -> bool, desc: &'t str, ) -> Result<ParseableStr<'t, B>, Box<Expected<'t, B>>>

Expect 1 character for which pred must return true, return the string making up the remainder.

Source

pub fn take_identifier( &self, ) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>

Source

pub fn drop_while(&self, pred: impl FnMut(char) -> bool) -> ParseableStr<'t, B>

Source

pub fn take_n_while( &self, n: usize, pred: impl FnMut(char) -> bool, desc: &'t str, ) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>

Take n characters matching pred. Does not check whether there are more than n characters matching pred, just returns what was found so far.

Source

pub fn take_nrange_while( &self, n_min: usize, n_max: usize, pred: impl FnMut(char) -> bool, desc: &'t str, ) -> Result<(ParseableStr<'t, B>, ParseableStr<'t, B>), Box<Expected<'t, B>>>

Take n_min to n_max (inclusive) characters matching pred. Does not check whether there are more than n_max characters matching pred, just returns what was found so far.

Source

pub fn drop_whitespace(&self) -> ParseableStr<'t, B>

Source

pub fn split_str<'r, 'n>( &'r self, separator: &'n str, omit_empty_last_item: bool, ) -> Box<dyn Iterator<Item = ParseableStr<'t, B>> + 'n>
where 't: 'n, 'r: 'n,

Split on a fixed string, separator; the separator string is not included in the returned parts. If omit_empty_last_item is true, if there’s an empty string after the last separator, it is not reported as an item.

Trait Implementations§

Source§

impl<'t, B: Backing> Clone for ParseableStr<'t, B>

Source§

fn clone(&self) -> Self

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<'t, B: Debug + Backing> Debug for ParseableStr<'t, B>

Source§

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

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

impl<'t, B: Backing> From<&'t B> for ParseableStr<'t, B>

Source§

fn from(s: &'t B) -> Self

Converts to this type from the input type.
Source§

impl<'r, 's, B: Backing> From<&'r ParseableStr<'s, B>> for StringParseContext<&'s B>
where &'s B: Backing,

Source§

fn from(value: &'r ParseableStr<'s, B>) -> Self

Converts to this type from the input type.
Source§

impl<'s, B: Backing> From<ParseableStr<'s, B>> for StringParseContext<&'s B>
where &'s B: Backing,

Source§

fn from(value: ParseableStr<'s, B>) -> Self

Converts to this type from the input type.
Source§

impl<'s, B: Backing> IntoOwningBacking<<B as ToOwned>::Owned> for ParseableStr<'s, B>
where &'s B: Backing, B::Owned: Backing,

Source§

impl<'t, B: PartialEq + Backing> PartialEq for ParseableStr<'t, B>

Source§

fn eq(&self, other: &ParseableStr<'t, B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'t, B: Copy + Backing> Copy for ParseableStr<'t, B>

Source§

impl<'t, B: Eq + Backing> Eq for ParseableStr<'t, B>

Source§

impl<'t, B: Backing> StructuralPartialEq for ParseableStr<'t, B>

Auto Trait Implementations§

§

impl<'t, B> Freeze for ParseableStr<'t, B>

§

impl<'t, B> RefUnwindSafe for ParseableStr<'t, B>
where B: RefUnwindSafe,

§

impl<'t, B> Send for ParseableStr<'t, B>
where B: Sync,

§

impl<'t, B> Sync for ParseableStr<'t, B>
where B: Sync,

§

impl<'t, B> Unpin for ParseableStr<'t, B>

§

impl<'t, B> UnwindSafe for ParseableStr<'t, B>
where B: 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.