Type Alias 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.

Aliased Type§

struct Str(/* private fields */);

Implementations§

source§

impl Str

source

pub fn slice<R>(&self, range: R) -> Strwhere str: Index<R, Output = str>,

Extracts a subslice of the string as an owned Str.

Panics

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

source

pub fn slice_ref(&self, subslice: &str) -> Self

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

pub const fn from_static(s: &'static str) -> Self

Create Str from static string in O(1).

Trait Implementations§

source§

impl From<Box<str>> for Str

source§

fn from(s: Box<str>) -> Self

Converts to this type from the input type.
source§

impl From<StrInner<BytesMut>> for Str

source§

fn from(s: StrMut) -> Self

Converts to this type from the input type.
source§

impl From<String> for Str

source§

fn from(s: String) -> Self

Converts to this type from the input type.