Type Definition bytes_utils::string::Str

source · []
pub type Str = StrInner<Bytes>;
Expand description

An immutable variant of Bytes-backed string.

The methods and their documentation are on StrInner, but users are mostly expected to use this and the StrMut aliases.

Implementations

Extracts a subslice of the string as an owned Str.

Panics

If the byte indices in the range are not on char boundaries.

Extracts owned representation of the slice passed.

This method accepts a string sub-slice of self. It then extracts the slice but as the Str type. This makes it easier to use “ordinary” string parsing/manipulation and then go back to holding the Bytes-based representation.

This is zero-copy, the common part will be shared by reference counting.

Panics

If the provided slice is not a sub-slice of self. This is checked based on address of the slice, not on the content.

Example
let owned = Str::from("Hello World");
let borrowed_mid: &str = &owned[2..5];

let mid: Str = owned.slice_ref(borrowed_mid);
assert_eq!("Hello World", owned);
assert_eq!("llo", mid);

Trait Implementations

Performs the conversion.