bytes_utils::string

Type Alias StrMut

Source
pub type StrMut = StrInner<BytesMut>;
Expand description

A mutable variant of BytesMut-backed string.

Unlike Str, this one allows modifications (mostly additions), but also doesn’t allow overlapping/shared chunks.

This is internally backed by the StrInner type, so the documentation of the methods are on that.

Aliased Type§

struct StrMut(/* private fields */);

Implementations§

Source§

impl StrMut

Source

pub fn split_built(&mut self) -> StrMut

Splits and returns the part of already built string, but keeps the extra capacity.

Source§

impl<S: Storage> StrInner<S>

Source

pub fn new() -> Self

Creates an empty instance.

Source

pub fn into_inner(self) -> S

Extracts the inner byte storage.

Source

pub fn inner(&self) -> &S

Access to the inner storage.

Source

pub fn from_inner(s: S) -> Result<Self, Utf8Error<S>>

Creates an instance from an existing byte storage.

It may fail if the content is not valid UTF8.

A try_from may be used instead.

Source

pub const unsafe fn from_inner_unchecked(s: S) -> Self

Same as from_inner, but without the checks.

§Safety

The caller must ensure content is valid UTF8.

Source

pub fn split_at_bytes(self, at: usize) -> (Self, Self)

Splits the string into two at the given index.

§Panics

If the index is not at char boundary.

Source

pub fn split_whitespace_bytes(self) -> impl Iterator<Item = Self>

Splits into whitespace separated “words”.

This acts like split_whitespace, but yields owned instances. It doesn’t clone the content, it just increments some reference counts.

Source

pub fn split_ascii_whitespace_bytes(self) -> impl Iterator<Item = Self>

Splits into whitespace separated “words”.

This acts like split_ascii_whitespace, but yields owned instances. This doesn’t clone the content, it just increments some reference counts.

Source

pub fn lines_bytes(self) -> impl Iterator<Item = Self>

Splits into lines.

This acts like lines, but yields owned instances. The content is not cloned, this just increments some reference counts.

Source

pub fn split_bytes<'s>(self, sep: &'s str) -> impl Iterator<Item = Self> + 's
where S: 's,

Splits with the provided separator.

This acts somewhat like split, but yields owned instances. Also, it accepts only string patters (since the Pattern is not stable ☹). The content is not cloned, this just increments some reference counts.

Source

pub fn splitn_bytes<'s>( self, n: usize, sep: &'s str, ) -> impl Iterator<Item = Self> + 's
where S: 's,

Splits max. n times according to the given pattern.

This acts somewhat like splitn, but yields owned instances. Also, it accepts only string patters (since the Pattern is not stable ☹). The content is not cloned, this just increments some reference counts.

Source

pub fn rsplit_bytes<'s>(self, sep: &'s str) -> impl Iterator<Item = Self> + 's
where S: 's,

A reverse version of split_bytes.

Source

pub fn rsplitn_bytes<'s>( self, n: usize, sep: &'s str, ) -> impl Iterator<Item = Self> + 's
where S: 's,

A reverse version of splitn_bytes.

Source§

impl<S: StorageMut> StrInner<S>

Source

pub fn push_str(&mut self, s: &str)

Appends a string.

Source

pub fn push(&mut self, c: char)

Appends one character.

Source

pub unsafe fn inner_mut(&mut self) -> &mut S

Provides mutable access to the inner buffer.

§Safety

The caller must ensure that the content stays valid UTF8.

Source

pub fn freeze(self) -> StrInner<S::Immutable>

Turns the mutable variant into an immutable one.

The advantage is that it can then be shared (also by small parts).

Trait Implementations

Source§

impl<S: StorageMut> Add<&str> for StrInner<S>

Source§

type Output = StrInner<S>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &str) -> Self::Output

Performs the + operation. Read more
Source§

impl<S: StorageMut> AddAssign<&str> for StrInner<S>

Source§

fn add_assign(&mut self, rhs: &str)

Performs the += operation. Read more
Source§

impl<S: StorageMut> AsMut<str> for StrInner<S>

Source§

fn as_mut(&mut self) -> &mut str

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<S, T> AsRef<T> for StrInner<S>
where S: Storage, str: AsRef<T>,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<S: Storage> Borrow<str> for StrInner<S>

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<S: StorageMut> BorrowMut<str> for StrInner<S>

Source§

fn borrow_mut(&mut self) -> &mut str

Mutably borrows from an owned value. Read more
Source§

impl<S: Clone> Clone for StrInner<S>

Source§

fn clone(&self) -> StrInner<S>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Storage> Debug for StrInner<S>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more
Source§

impl<S: Default> Default for StrInner<S>

Source§

fn default() -> StrInner<S>

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

impl<S: Storage> Deref for StrInner<S>

Source§

type Target = str

The resulting type after dereferencing.
Source§

fn deref(&self) -> &str

Dereferences the value.
Source§

impl<S: StorageMut> DerefMut for StrInner<S>

Source§

fn deref_mut(&mut self) -> &mut str

Mutably dereferences the value.
Source§

impl<S: Storage> Display for StrInner<S>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more
Source§

impl<'a, S: StorageMut> Extend<&'a String> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = &'a String>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, S: StorageMut> Extend<&'a char> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, S: StorageMut> Extend<&'a str> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<S: StorageMut> Extend<Box<str>> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = Box<str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, S: StorageMut> Extend<Cow<'a, str>> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<S: StorageMut> Extend<String> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = String>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<S: StorageMut> Extend<char> for StrInner<S>

Source§

fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, S> From<&'a String> for StrInner<S>
where S: Storage,

Source§

fn from(s: &'a String) -> Self

Converts to this type from the input type.
Source§

impl<'a, S> From<&'a str> for StrInner<S>
where S: Storage,

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'a, S> From<Cow<'a, str>> for StrInner<S>
where S: Storage,

Source§

fn from(s: Cow<'a, str>) -> Self

Converts to this type from the input type.
Source§

impl<'a, S> FromIterator<&'a String> for StrInner<S>
where S: Storage,

Source§

fn from_iter<T: IntoIterator<Item = &'a String>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, S> FromIterator<&'a str> for StrInner<S>
where S: Storage,

Source§

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<S> FromIterator<Box<str>> for StrInner<S>
where S: Storage,

Source§

fn from_iter<T: IntoIterator<Item = Box<str>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, S> FromIterator<Cow<'a, str>> for StrInner<S>
where S: Storage,

Source§

fn from_iter<T: IntoIterator<Item = Cow<'a, str>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<S> FromIterator<String> for StrInner<S>
where S: Storage,

Source§

fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<S: Storage> FromStr for StrInner<S>

Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<S: Storage> Hash for StrInner<S>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<S, I> Index<I> for StrInner<S>
where S: Storage, str: Index<I>,

Source§

type Output = <str as Index<I>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<S, I> IndexMut<I> for StrInner<S>
where S: StorageMut, str: IndexMut<I>,

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<S: Storage> Ord for StrInner<S>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, S: Storage> PartialEq<&'a mut str> for StrInner<S>

Source§

fn eq(&self, other: &&'a mut str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, S: Storage> PartialEq<&'a str> for StrInner<S>

Source§

fn eq(&self, other: &&'a str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Storage> PartialEq<Box<str>> for StrInner<S>

Source§

fn eq(&self, other: &Box<str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, S: Storage> PartialEq<Cow<'a, str>> for StrInner<S>

Source§

fn eq(&self, other: &Cow<'a, str>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Storage> PartialEq<String> for StrInner<S>

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Storage> PartialEq for StrInner<S>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, S: Storage> PartialOrd<&'a mut str> for StrInner<S>

Source§

fn partial_cmp(&self, other: &&'a mut str) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, S: Storage> PartialOrd<&'a str> for StrInner<S>

Source§

fn partial_cmp(&self, other: &&'a str) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S: Storage> PartialOrd<Box<str>> for StrInner<S>

Source§

fn partial_cmp(&self, other: &Box<str>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, S: Storage> PartialOrd<Cow<'a, str>> for StrInner<S>

Source§

fn partial_cmp(&self, other: &Cow<'a, str>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S: Storage> PartialOrd<String> for StrInner<S>

Source§

fn partial_cmp(&self, other: &String) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S: Storage> PartialOrd for StrInner<S>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<BytesMut> for StrInner<BytesMut>

Source§

type Error = Utf8Error<BytesMut>

The type returned in the event of a conversion error.
Source§

fn try_from(s: BytesMut) -> Result<Self, Utf8Error<BytesMut>>

Performs the conversion.
Source§

impl<S: StorageMut> Write for StrInner<S>

Source§

fn write_str(&mut self, s: &str) -> FmtResult

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

impl<S: Storage> Eq for StrInner<S>