Struct ntex_bytes::ByteString[][src]

pub struct ByteString(_);
Expand description

An immutable UTF-8 encoded string with Bytes as a storage.

Implementations

Creates a new empty ByteString.

Get a reference to the underlying bytes.

Get a reference to the underlying Bytes object.

Unwraps this ByteString into the underlying Bytes object.

Creates a new ByteString from a &'static str.

Returns a slice of self for the provided range.

This will increment the reference count for the underlying memory and return a new ByteString handle set to the slice.

This operation is O(1).

Examples

use ntex_bytes::ByteString;

let a = ByteString::from("hello world");
let b = a.slice(2..5);

assert_eq!(b, "llo");

Panics

Requires that begin <= end and end <= self.len(), otherwise slicing will panic.

Splits the bytestring into two at the given index.

Afterwards self contains elements [0, at), and the returned ByteString contains elements [at, len).

This is an O(1) operation that just increases the reference count and sets a few indices.

Examples

use ntex_bytes::ByteString;

let mut a = ByteString::from("hello world");
let b = a.split_off(5);

assert_eq!(a, "hello");
assert_eq!(b, " world");

Panics

Panics if at > len.

Splits the bytestring into two at the given index.

Afterwards self contains elements [at, len), and the returned Bytes contains elements [0, at).

This is an O(1) operation that just increases the reference count and sets a few indices.

Examples

use ntex_bytes::ByteString;

let mut a = ByteString::from("hello world");
let b = a.split_to(5);

assert_eq!(a, " world");
assert_eq!(b, "hello");

Panics

Panics if at > len.

Shortens the buffer to len bytes and dropping the rest.

Creates a new ByteString from a Bytes.

Safety

This function is unsafe because it does not check the bytes passed to it are valid UTF-8. If this constraint is violated, it may cause memory unsafety issues with future users of the ByteString, as we assume that ByteStrings are valid UTF-8. However, the most likely issue is that the data gets corrupted.

Trait Implementations

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

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 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

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.

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.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.