pub struct NomBytes(_, _);
Expand description

A wrapper around bytes::Bytes to be able to use it with nom.

Implementations

Creates a new NomBytes wrapping the provided Bytes.

Examples
use bytes::Bytes;
use nombytes::NomBytes;

let b = Bytes::new();
let nb = NomBytes::new(b);

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.to_str(), "hello");
Panics

Panics if the Bytes slice is not UTF-8.

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.

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");

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");

Returns the values from the inner representation of this type.

See into_bytes for an explanation of why this inner representation exists.

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

Casts the input type to a byte slice

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Compares self to another value for equality

Compares self to another value for equality independently of the case. Read more

Compares self to another value for equality

Compares self to another value for equality independently of the case. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

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

An iterator over the input type, producing the item and its position for use with Slice. If we’re iterating over &str, the position corresponds to the byte index of the character Read more

An iterator over the input type, producing the item

Returns an iterator over the elements and their byte offsets

Returns an iterator over the elements

Finds the byte position of the element

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

Calculates the input length, as indicated by its name, and the name of the trait itself Read more

Returns a slice of count bytes. panics if count > length

Split the stream at the count byte offset. panics if count > length

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

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

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

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

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

Offset between the first byte of self and the first byte of the argument

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Slices self according to the range argument

Slices self according to the range argument

Slices self according to the range argument

Slices self according to the range argument

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.