smartstring::alias

Type Alias String

Source
pub type String = SmartString<LazyCompact>;
Expand description

A convenience alias for a LazyCompact layout SmartString.

Just pretend it’s a String!

Aliased Type§

struct String { /* private fields */ }

Implementations

Source§

impl SmartString<LazyCompact>

Source

pub const fn new_const() -> Self

Construct an empty string.

This is a const fn version of SmartString::new. It’s a temporary measure while we wait for trait bounds on type arguments to const fns to stabilise, and will be deprecated once this happens.

Source§

impl<Mode: SmartStringMode> SmartString<Mode>

Source

pub fn new() -> Self

Construct an empty string.

Source

pub fn len(&self) -> usize

Return the length in bytes of the string.

Note that this may differ from the length in chars.

Source

pub fn is_empty(&self) -> bool

Test whether the string is empty.

Source

pub fn is_inline(&self) -> bool

Test whether the string is currently inlined.

Source

pub fn as_str(&self) -> &str

Get a reference to the string as a string slice.

Source

pub fn as_mut_str(&mut self) -> &mut str

Get a reference to the string as a mutable string slice.

Source

pub fn capacity(&self) -> usize

Return the currently allocated capacity of the string.

Note that if this is a boxed string, it returns String::capacity(), but an inline string always returns MAX_INLINE.

Note also that if a boxed string is converted into an inline string, its capacity is deallocated, and if the inline string is promoted to a boxed string in the future, it will be reallocated with a default capacity.

Source

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

Push a character to the end of the string.

Source

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

Copy a string slice onto the end of the string.

Source

pub fn shrink_to_fit(&mut self)

Shrink the capacity of the string to fit its contents exactly.

This has no effect on inline strings, which always have a fixed capacity. Thus, it’s not safe to assume that capacity() will equal len() after calling this.

Calling this on a LazyCompact string that is currently heap allocated but is short enough to be inlined will deallocate the heap allocation and convert it to an inline string.

Source

pub fn truncate(&mut self, new_len: usize)

Truncate the string to new_len bytes.

If new_len is larger than the string’s current length, this does nothing. If new_len isn’t on a UTF-8 character boundary, this method panics.

Source

pub fn pop(&mut self) -> Option<char>

Pop a char off the end of the string.

Source

pub fn remove(&mut self, index: usize) -> char

Remove a char from the string at the given index.

If the index doesn’t fall on a UTF-8 character boundary, this method panics.

Source

pub fn insert(&mut self, index: usize, ch: char)

Insert a char into the string at the given index.

If the index doesn’t fall on a UTF-8 character boundary, this method panics.

Source

pub fn insert_str(&mut self, index: usize, string: &str)

Insert a string slice into the string at the given index.

If the index doesn’t fall on a UTF-8 character boundary, this method panics.

Source

pub fn split_off(&mut self, index: usize) -> Self

Split the string into two at the given index.

Returns the content to the right of the index as a new string, and removes it from the original.

If the index doesn’t fall on a UTF-8 character boundary, this method panics.

Source

pub fn clear(&mut self)

Clear the string.

This causes any memory reserved by the string to be immediately deallocated.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(char) -> bool,

Filter out chars not matching a predicate.

Source

pub fn drain<R>(&mut self, range: R) -> Drain<'_, Mode>
where R: RangeBounds<usize>,

Construct a draining iterator over a given range.

This removes the given range from the string, and returns an iterator over the removed chars.

Source

pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
where R: RangeBounds<usize>,

Replaces a range with the contents of a string slice.

Trait Implementations

Source§

impl<Mode: SmartStringMode> Add<&SmartString<Mode>> for SmartString<Mode>

Source§

type Output = SmartString<Mode>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<Mode: SmartStringMode> Add<&String> for SmartString<Mode>

Source§

type Output = SmartString<Mode>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<Mode: SmartStringMode> Add<&str> for SmartString<Mode>

Source§

type Output = SmartString<Mode>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<Mode: SmartStringMode> Add<String> for SmartString<Mode>

Source§

type Output = SmartString<Mode>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<Mode: SmartStringMode> Add for SmartString<Mode>

Source§

type Output = SmartString<Mode>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<Mode: SmartStringMode> AsMut<str> for SmartString<Mode>

Source§

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

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

impl<Mode: SmartStringMode> AsRef<[u8]> for SmartString<Mode>

Source§

fn as_ref(&self) -> &[u8]

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

impl<Mode: SmartStringMode> AsRef<str> for SmartString<Mode>

Source§

fn as_ref(&self) -> &str

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

impl<Mode: SmartStringMode> Borrow<str> for SmartString<Mode>

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<Mode: SmartStringMode> BorrowMut<str> for SmartString<Mode>

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<Mode: SmartStringMode> Clone for SmartString<Mode>

Source§

fn clone(&self) -> Self

Clone a SmartString.

If the string is inlined, this is a Copy operation. Otherwise, a string with the same capacity as the source is allocated.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Mode: SmartStringMode> Debug for SmartString<Mode>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

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

impl<Mode: SmartStringMode> Default for SmartString<Mode>

Source§

fn default() -> Self

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

impl<Mode: SmartStringMode> Deref for SmartString<Mode>

Source§

type Target = str

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Mode: SmartStringMode> DerefMut for SmartString<Mode>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Mode: SmartStringMode> Display for SmartString<Mode>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

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

impl<Mode: SmartStringMode> Drop for SmartString<Mode>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, Mode: SmartStringMode + 'a> Extend<&'a SmartString<Mode>> for SmartString<Mode>

Source§

fn extend<I: IntoIterator<Item = &'a SmartString<Mode>>>(&mut self, iter: I)

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, Mode: SmartStringMode> Extend<&'a String> for SmartString<Mode>

Source§

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

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, Mode: SmartStringMode> Extend<&'a char> for SmartString<Mode>

Source§

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

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, Mode: SmartStringMode> Extend<&'a str> for SmartString<Mode>

Source§

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

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<Mode: SmartStringMode> Extend<SmartString<Mode>> for SmartString<Mode>

Source§

fn extend<I: IntoIterator<Item = SmartString<Mode>>>(&mut self, iter: I)

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<Mode: SmartStringMode> Extend<String> for SmartString<Mode>

Source§

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

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<Mode: SmartStringMode> Extend<char> for SmartString<Mode>

Source§

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

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<Mode: SmartStringMode> From<&String> for SmartString<Mode>

Source§

fn from(string: &String) -> Self

Converts to this type from the input type.
Source§

impl<Mode: SmartStringMode> From<&mut str> for SmartString<Mode>

Source§

fn from(string: &mut str) -> Self

Converts to this type from the input type.
Source§

impl<Mode: SmartStringMode> From<&str> for SmartString<Mode>

Source§

fn from(string: &str) -> Self

Converts to this type from the input type.
Source§

impl<Mode: SmartStringMode> From<Box<str>> for SmartString<Mode>

Source§

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

Converts to this type from the input type.
Source§

impl<Mode: SmartStringMode> From<Cow<'_, str>> for SmartString<Mode>

Source§

fn from(string: Cow<'_, str>) -> Self

Converts to this type from the input type.
Source§

impl<Mode: SmartStringMode> From<String> for SmartString<Mode>

Source§

fn from(string: String) -> Self

Converts to this type from the input type.
Source§

impl<'a, Mode: SmartStringMode + 'a> FromIterator<&'a SmartString<Mode>> for SmartString<Mode>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a, Mode: SmartStringMode> FromIterator<&'a String> for SmartString<Mode>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a, Mode: SmartStringMode> FromIterator<&'a str> for SmartString<Mode>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<Mode: SmartStringMode> FromIterator<SmartString<Mode>> for SmartString<Mode>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<Mode: SmartStringMode> FromIterator<String> for SmartString<Mode>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<Mode: SmartStringMode> FromIterator<char> for SmartString<Mode>

Source§

fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<Mode: SmartStringMode> FromStr for SmartString<Mode>

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<Mode: SmartStringMode> Hash for SmartString<Mode>

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<Mode: SmartStringMode> Index<Range<usize>> for SmartString<Mode>

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

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

impl<Mode: SmartStringMode> Index<RangeFrom<usize>> for SmartString<Mode>

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

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

impl<Mode: SmartStringMode> Index<RangeFull> for SmartString<Mode>

Source§

type Output = str

The returned type after indexing.
Source§

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

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

impl<Mode: SmartStringMode> Index<RangeInclusive<usize>> for SmartString<Mode>

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

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

impl<Mode: SmartStringMode> Index<RangeTo<usize>> for SmartString<Mode>

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

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

impl<Mode: SmartStringMode> Index<RangeToInclusive<usize>> for SmartString<Mode>

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

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

impl<Mode: SmartStringMode> IndexMut<Range<usize>> for SmartString<Mode>

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

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

impl<Mode: SmartStringMode> IndexMut<RangeFrom<usize>> for SmartString<Mode>

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

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

impl<Mode: SmartStringMode> IndexMut<RangeFull> for SmartString<Mode>

Source§

fn index_mut(&mut self, _index: RangeFull) -> &mut Self::Output

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

impl<Mode: SmartStringMode> IndexMut<RangeInclusive<usize>> for SmartString<Mode>

Source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

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

impl<Mode: SmartStringMode> IndexMut<RangeTo<usize>> for SmartString<Mode>

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

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

impl<Mode: SmartStringMode> IndexMut<RangeToInclusive<usize>> for SmartString<Mode>

Source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

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

impl<Mode: SmartStringMode> Ord for SmartString<Mode>

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<Mode: SmartStringMode> PartialEq<&str> for SmartString<Mode>

Source§

fn eq(&self, other: &&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<Mode: SmartStringMode> PartialEq<String> for SmartString<Mode>

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<Mode: SmartStringMode> PartialEq<str> for SmartString<Mode>

Source§

fn eq(&self, other: &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<Mode: SmartStringMode> PartialEq for SmartString<Mode>

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<Mode: SmartStringMode> PartialOrd<str> for SmartString<Mode>

Source§

fn partial_cmp(&self, other: &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<Mode: SmartStringMode> PartialOrd for SmartString<Mode>

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<Mode: SmartStringMode> Write for SmartString<Mode>

Source§

fn write_str(&mut self, string: &str) -> Result<(), Error>

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<Mode: SmartStringMode> Eq for SmartString<Mode>