pub struct NomBytes(_, _);
Expand description
A wrapper around bytes::Bytes
to be able to use it with nom
.
Implementations
sourceimpl NomBytes
impl NomBytes
sourcepub fn try_to_str(&self) -> Result<&str, Utf8Error>
pub fn try_to_str(&self) -> Result<&str, Utf8Error>
Returns a string slice to the contents of the inner Bytes
.
Examples
use bytes::Bytes;
use nombytes::NomBytes;
let nb = NomBytes::new(Bytes::from("hello"));
assert_eq!(nb.try_to_str().unwrap(), "hello");
Errors
Returns Err
if the Bytes
slice is not UTF-8 with a description
as to why the provided slice is not UTF-8.
sourcepub fn to_bytes(&self) -> Bytes
pub fn to_bytes(&self) -> Bytes
Returns a Bytes
representing the real state of the inner one.
Be careful using a Bytes
returned from this function to create
a new NomBytes
for use in the same parsing session, as due to
an optimization in Bytes
, creating an empty slice (e.g. asking
for the slice of 0..0
or ..0
, which nom
sometimes does)
results in a Bytes
that is unrelated to its source, which
causes later offset calculations to give incorrect results.
This behavior is accounted for internally, so as long as you stick
to only using NomBytes
directly without going to Bytes
and back,
you won’t be affected by this optimization behavior.
Examples
use bytes::Bytes;
use nombytes::NomBytes;
let nb = NomBytes::new(Bytes::from("hello"));
let b = nb.to_bytes();
assert_eq!(b.as_ref(), b"hello");
sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Returns a Bytes
representing the real state of the inner one.
Be careful using a Bytes
returned from this function to create
a new NomBytes
for use in the same parsing session, as due to
an optimization in Bytes
, creating an empty slice (e.g. asking
for the slice of 0..0
or ..0
, which nom
sometimes does)
results in a Bytes
that is unrelated to its source, which
causes later offset calculations to give incorrect results.
This behavior is accounted for internally, so as long as you stick
to only using NomBytes
directly without going to Bytes
and back,
you won’t be affected by this optimization behavior.
Examples
use bytes::Bytes;
use nombytes::NomBytes;
let nb = NomBytes::new(Bytes::from("hello"));
let b = nb.into_bytes();
assert_eq!(b.as_ref(), b"hello");
sourcepub fn into_raw(self) -> (Bytes, Option<RangeType<usize>>)
pub fn into_raw(self) -> (Bytes, Option<RangeType<usize>>)
Returns the values from the inner representation of this type.
See into_bytes
for an explanation of why this
inner representation exists.
sourcepub fn from_raw((bytes, range_type): (Bytes, Option<RangeType<usize>>)) -> Self
pub fn from_raw((bytes, range_type): (Bytes, Option<RangeType<usize>>)) -> Self
Returns a new NomBytes
using the raw values passed in. If these
values represent something invalid, you’ll likely see incorrect
behavior or even panics. Regular usage should create values using
new
instead.
See into_bytes
for an explanation of why this
inner representation exists.
Trait Implementations
sourceimpl Compare<&str> for NomBytes
impl Compare<&str> for NomBytes
sourcefn compare(&self, t: &str) -> CompareResult
fn compare(&self, t: &str) -> CompareResult
Compares self to another value for equality
sourcefn compare_no_case(&self, t: &str) -> CompareResult
fn compare_no_case(&self, t: &str) -> CompareResult
Compares self to another value for equality independently of the case. Read more
sourceimpl Compare<NomBytes> for NomBytes
impl Compare<NomBytes> for NomBytes
sourcefn compare(&self, t: NomBytes) -> CompareResult
fn compare(&self, t: NomBytes) -> CompareResult
Compares self to another value for equality
sourcefn compare_no_case(&self, t: NomBytes) -> CompareResult
fn compare_no_case(&self, t: NomBytes) -> CompareResult
Compares self to another value for equality independently of the case. Read more
sourceimpl<'de> Deserialize<'de> for NomBytes
impl<'de> Deserialize<'de> for NomBytes
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl InputIter for NomBytes
impl InputIter for NomBytes
sourcefn iter_indices(&self) -> Self::Iter
fn iter_indices(&self) -> Self::Iter
Returns an iterator over the elements and their byte offsets
sourcefn iter_elements(&self) -> Self::IterElem
fn iter_elements(&self) -> Self::IterElem
Returns an iterator over the elements
sourceimpl InputLength for NomBytes
impl InputLength for NomBytes
sourceimpl InputTake for NomBytes
impl InputTake for NomBytes
sourcefn take_split(&self, count: usize) -> (Self, Self)
fn take_split(&self, count: usize) -> (Self, Self)
Split the stream at the count
byte offset. panics if count > length
sourceimpl InputTakeAtPosition for NomBytes
impl InputTakeAtPosition for NomBytes
type Item = <NomBytes as InputIter>::Item
type Item = <NomBytes as InputIter>::Item
The current input type is a sequence of that Item
type. Read more
sourcefn split_at_position<P, E: ParseError<Self>>(
&self,
predicate: P
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position<P, E: ParseError<Self>>(
&self,
predicate: P
) -> IResult<Self, Self, E> where
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
sourcefn split_at_position1<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position1<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
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
sourcefn split_at_position_complete<P, E: ParseError<Self>>(
&self,
predicate: P
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position_complete<P, E: ParseError<Self>>(
&self,
predicate: P
) -> IResult<Self, Self, E> where
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
sourcefn split_at_position1_complete<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
P: Fn(Self::Item) -> bool,
fn split_at_position1_complete<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind
) -> IResult<Self, Self, E> where
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
sourceimpl Ord for NomBytes
impl Ord for NomBytes
sourceimpl PartialOrd<NomBytes> for NomBytes
impl PartialOrd<NomBytes> for NomBytes
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SourceCode for NomBytes
impl SourceCode for NomBytes
sourcefn read_span<'a>(
&'a self,
span: &SourceSpan,
context_lines_before: usize,
context_lines_after: usize
) -> Result<Box<dyn SpanContents<'a> + 'a>, MietteError>
fn read_span<'a>(
&'a self,
span: &SourceSpan,
context_lines_before: usize,
context_lines_after: usize
) -> Result<Box<dyn SpanContents<'a> + 'a>, MietteError>
Read the bytes for a specific span from this SourceCode, keeping a certain number of lines before and after the span as context. Read more
impl Eq for NomBytes
Auto Trait Implementations
impl RefUnwindSafe for NomBytes
impl Send for NomBytes
impl Sync for NomBytes
impl Unpin for NomBytes
impl UnwindSafe for NomBytes
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more