Type Definition bytes_utils::string::Str[][src]

type Str = StrInner<Bytes>;

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

impl Str[src]

pub fn slice<R>(&self, range: R) -> Str where
    str: Index<R, Output = str>, 
[src]

Extracts a subslice of the string as an owned Str.

Panics

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

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

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

impl From<StrInner<BytesMut>> for Str[src]