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
impl ParseContainer
Sourcepub fn new(raw: Arc<String>) -> Self
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()));
Sourcepub fn is_empty(&self) -> bool
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());
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of self
§Examples
let container = ParseContainer::from("foo");
assert_eq!(container.len(), 3);
Sourcepub fn as_str(&self) -> &str
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");
Sourcepub fn split_at(&self, mid: usize) -> (Self, Self)
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
impl Borrow<str> for ParseContainer
Source§impl Clone for ParseContainer
impl Clone for ParseContainer
Source§fn clone(&self) -> ParseContainer
fn clone(&self) -> ParseContainer
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ParseContainer
impl Debug for ParseContainer
Source§impl Display for ParseContainer
impl Display for ParseContainer
Source§impl From<&[ParseContainer]> for ParseContainer
impl From<&[ParseContainer]> for ParseContainer
Source§fn from(x: &[ParseContainer]) -> Self
fn from(x: &[ParseContainer]) -> Self
Converts to this type from the input type.
Source§impl<const N: usize> From<&[ParseContainer; N]> for ParseContainer
impl<const N: usize> From<&[ParseContainer; N]> for ParseContainer
Source§fn from(x: &[ParseContainer; N]) -> Self
fn from(x: &[ParseContainer; N]) -> Self
Converts to this type from the input type.
Source§impl From<&str> for ParseContainer
impl From<&str> for ParseContainer
Source§impl From<String> for ParseContainer
impl From<String> for ParseContainer
Source§impl From<Vec<ParseContainer>> for ParseContainer
impl From<Vec<ParseContainer>> for ParseContainer
Source§fn from(x: Vec<ParseContainer>) -> Self
fn from(x: Vec<ParseContainer>) -> Self
Converts to this type from the input type.
Source§impl Input for ParseContainer
impl Input for ParseContainer
Source§type Iter = IntoIter<<ParseContainer as Input>::Item>
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)>
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 characterSource§fn input_len(&self) -> usize
fn input_len(&self) -> usize
Calculates the input length, as indicated by its name,
and the name of the trait itself
Source§fn take_from(&self, index: usize) -> Self
fn take_from(&self, index: usize) -> Self
Returns a slice starting at
index
bytes. panics if index > lengthSource§fn take_split(&self, index: usize) -> (Self, Self)
fn take_split(&self, index: usize) -> (Self, Self)
Split the stream at the
index
byte offset. panics if index > lengthSource§fn position<P>(&self, predicate: P) -> Option<usize>
fn position<P>(&self, predicate: P) -> Option<usize>
Returns the byte position of the first element satisfying the predicate
Source§fn iter_elements(&self) -> <Self as Input>::Iter
fn iter_elements(&self) -> <Self as Input>::Iter
Returns an iterator over the elements
Source§fn iter_indices(&self) -> <Self as Input>::IterIndices
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>
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>>
fn split_at_position<P, E>(&self, predicate: P) -> Result<(Self, Self), Err<E>>
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>>
fn split_at_position1<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
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>>
fn split_at_position_complete<P, E>( &self, predicate: P, ) -> Result<(Self, Self), Err<E>>
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>>
fn split_at_position1_complete<P, E>( &self, predicate: P, e: ErrorKind, ) -> Result<(Self, Self), Err<E>>
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>>>
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>>>
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>>>
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>>>
mode version of split_at_position
Source§impl PartialEq<&str> for ParseContainer
impl PartialEq<&str> for ParseContainer
Source§impl PartialEq<ParseContainer> for &str
impl PartialEq<ParseContainer> for &str
Source§impl PartialEq for ParseContainer
impl PartialEq for ParseContainer
Auto Trait Implementations§
impl Freeze for ParseContainer
impl RefUnwindSafe for ParseContainer
impl Send for ParseContainer
impl Sync for ParseContainer
impl Unpin for ParseContainer
impl UnwindSafe for ParseContainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more