Struct ParseContainer

Source
pub struct ParseContainer { /* private fields */ }
Expand description

An intermediate representation to parse.

The ParseContainer has a shared pointer of the original String and the pair of sub-string position (begin and end),

Implementations§

Source§

impl ParseContainer

Source

pub fn new(raw: Arc<String>) -> Self

Creates a new ParseContainer from the original string. The inner positions are held in the entirety of the original string.

§Examples
let _ = ParseContainer::new(Arc::new("foo".to_string()));
Source

pub fn is_empty(&self) -> bool

Returns true if self has a length of zero

§Examples
let container = ParseContainer::from("");
assert!(container.is_empty());
let container = ParseContainer::from("foo");
let (_rest, parsed) = container.split_at(0);
assert!(parsed.is_empty());
let (rest, _parsed) = container.split_at(container.len());
assert!(rest.is_empty());
Source

pub fn len(&self) -> usize

Returns the length of self

§Examples
let container = ParseContainer::from("foo");
assert_eq!(container.len(), 3);
Source

pub fn as_str(&self) -> &str

Returns a string slice of the sub-string

§Examples
let container = ParseContainer::from("foo");
let s: &str = container.as_str(); // Returns `&str`
assert_eq!(s, "foo");
Source

pub fn split_at(&self, mid: usize) -> (Self, Self)

Splits into two sub-strings by mid

  • mid - A position to split.
§Panics

Panics if mid is past the end of the sub-string.

§Examples
let container = ParseContainer::from("Hello, World!");
let (rest, parsed) = container.split_at(7);
assert_eq!(rest, "World!");
assert_eq!(parsed, "Hello, ");

let (rest, parsed) = container.split_at(0);
assert_eq!(rest, "Hello, World!");
assert_eq!(parsed, "");

let (rest, parsed) = container.split_at(container.len());
assert_eq!(rest, "");
assert_eq!(parsed, "Hello, World!");

Trait Implementations§

Source§

impl Borrow<str> for ParseContainer

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl Clone for ParseContainer

Source§

fn clone(&self) -> ParseContainer

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 Debug for ParseContainer

Source§

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

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

impl Display for ParseContainer

Source§

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

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

impl From<&[ParseContainer]> for ParseContainer

Source§

fn from(x: &[ParseContainer]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<&[ParseContainer; N]> for ParseContainer

Source§

fn from(x: &[ParseContainer; N]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for ParseContainer

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ParseContainer

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<ParseContainer>> for ParseContainer

Source§

fn from(x: Vec<ParseContainer>) -> Self

Converts to this type from the input type.
Source§

impl Input for ParseContainer

Source§

type Item = char

The current input type is a sequence of that Item type. Read more
Source§

type Iter = IntoIter<<ParseContainer as Input>::Item>

An iterator over the input type, producing the item
Source§

type IterIndices = IntoIter<(usize, <ParseContainer as Input>::Item)>

An iterator over the input type, producing the item and its byte position If we’re iterating over &str, the position corresponds to the byte index of the character
Source§

fn input_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself
Source§

fn take(&self, index: usize) -> Self

Returns a slice of index bytes. panics if index > length
Source§

fn take_from(&self, index: usize) -> Self

Returns a slice starting at index bytes. panics if index > length
Source§

fn take_split(&self, index: usize) -> (Self, Self)

Split the stream at the index byte offset. panics if index > length
Source§

fn position<P>(&self, predicate: P) -> Option<usize>
where P: Fn(Self::Item) -> bool,

Returns the byte position of the first element satisfying the predicate
Source§

fn iter_elements(&self) -> <Self as Input>::Iter

Returns an iterator over the elements
Source§

fn iter_indices(&self) -> <Self as Input>::IterIndices

Returns an iterator over the elements and their byte offsets
Source§

fn slice_index(&self, count: usize) -> Result<usize, Needed>

Get the byte offset from the element’s position in the stream
Source§

fn split_at_position<P, E>(&self, predicate: P) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true, and returns the input up to this position. Read more
Source§

fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true and returns the input up to this position. Read more
Source§

fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true, and returns the input up to this position. Read more
Source§

fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
where E: ParseError<Self>, P: Fn(Self::Item) -> bool,

Looks for the first element of the input type for which the condition returns true and returns the input up to this position. Read more
Source§

fn split_at_position_mode<OM, P, E>( &self, predicate: P, ) -> Result<(Self, <<OM as OutputMode>::Output as Mode>::Output<Self>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<Self>, P: Fn(Self::Item) -> bool,

mode version of split_at_position
Source§

fn split_at_position_mode1<OM, P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, <<OM as OutputMode>::Output as Mode>::Output<Self>), Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>>
where OM: OutputMode, E: ParseError<Self>, P: Fn(Self::Item) -> bool,

mode version of split_at_position
Source§

impl PartialEq<&str> for ParseContainer

Source§

fn eq(&self, rhs: &&str) -> 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 PartialEq<ParseContainer> for &str

Source§

fn eq(&self, rhs: &ParseContainer) -> 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 PartialEq for ParseContainer

Source§

fn eq(&self, rhs: &ParseContainer) -> 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.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more