pub struct NomBytes(/* private fields */);
Expand description
A wrapper around bytes::Bytes
to be able to use it with nom
.
Implementations§
Source§impl 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§
Source§impl Compare<&str> for NomBytes
impl Compare<&str> for NomBytes
Source§fn compare(&self, t: &str) -> CompareResult
fn compare(&self, t: &str) -> CompareResult
Source§fn compare_no_case(&self, t: &str) -> CompareResult
fn compare_no_case(&self, t: &str) -> CompareResult
Source§impl Compare<NomBytes> for NomBytes
impl Compare<NomBytes> for NomBytes
Source§fn compare(&self, t: NomBytes) -> CompareResult
fn compare(&self, t: NomBytes) -> CompareResult
Source§fn compare_no_case(&self, t: NomBytes) -> CompareResult
fn compare_no_case(&self, t: NomBytes) -> CompareResult
Source§impl<'de> Deserialize<'de> for NomBytes
impl<'de> Deserialize<'de> for NomBytes
Source§fn 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>,
Source§impl InputIter for NomBytes
impl InputIter for NomBytes
Source§type Iter = Enumerate<<NomBytes as InputIter>::IterElem>
type Iter = Enumerate<<NomBytes as InputIter>::IterElem>
&str
, the position
corresponds to the byte index of the characterSource§fn iter_indices(&self) -> Self::Iter
fn iter_indices(&self) -> Self::Iter
Source§fn iter_elements(&self) -> Self::IterElem
fn iter_elements(&self) -> Self::IterElem
Source§impl InputLength for NomBytes
impl InputLength for NomBytes
Source§impl InputTakeAtPosition for NomBytes
impl InputTakeAtPosition for NomBytes
Source§type Item = <NomBytes as InputIter>::Item
type Item = <NomBytes as InputIter>::Item
Item
type. Read moreSource§fn split_at_position<P, E: ParseError<Self>>(
&self,
predicate: P,
) -> IResult<Self, Self, E>
fn split_at_position<P, E: ParseError<Self>>( &self, predicate: P, ) -> IResult<Self, Self, E>
Source§fn split_at_position1<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind,
) -> IResult<Self, Self, E>
fn split_at_position1<P, E: ParseError<Self>>( &self, predicate: P, e: ErrorKind, ) -> IResult<Self, Self, E>
Source§fn split_at_position_complete<P, E: ParseError<Self>>(
&self,
predicate: P,
) -> IResult<Self, Self, E>
fn split_at_position_complete<P, E: ParseError<Self>>( &self, predicate: P, ) -> IResult<Self, Self, E>
Source§fn split_at_position1_complete<P, E: ParseError<Self>>(
&self,
predicate: P,
e: ErrorKind,
) -> IResult<Self, Self, E>
fn split_at_position1_complete<P, E: ParseError<Self>>( &self, predicate: P, e: ErrorKind, ) -> IResult<Self, Self, E>
Source§impl Ord for NomBytes
impl Ord for NomBytes
Source§impl PartialOrd for NomBytes
impl PartialOrd for NomBytes
Source§impl SourceCode for NomBytes
Available on crate feature miette
only.
impl SourceCode for NomBytes
miette
only.