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>
impl SmartString<LazyCompact>
Sourcepub const fn new_const() -> Self
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 fn
s to stabilise, and will be deprecated
once this happens.
Source§impl<Mode: SmartStringMode> SmartString<Mode>
impl<Mode: SmartStringMode> SmartString<Mode>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the length in bytes of the string.
Note that this may differ from the length in char
s.
Sourcepub fn as_mut_str(&mut self) -> &mut str
pub fn as_mut_str(&mut self) -> &mut str
Get a reference to the string as a mutable string slice.
Sourcepub fn capacity(&self) -> usize
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.
Sourcepub fn shrink_to_fit(&mut self)
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.
Sourcepub fn truncate(&mut self, new_len: usize)
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.
Sourcepub fn remove(&mut self, index: usize) -> char
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.
Sourcepub fn insert(&mut self, index: usize, ch: char)
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.
Sourcepub fn insert_str(&mut self, index: usize, string: &str)
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.
Sourcepub fn split_off(&mut self, index: usize) -> Self
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.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the string.
This causes any memory reserved by the string to be immediately deallocated.
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, Mode> ⓘwhere
R: RangeBounds<usize>,
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 char
s.
Sourcepub fn replace_range<R>(&mut self, range: R, replace_with: &str)where
R: RangeBounds<usize>,
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>
impl<Mode: SmartStringMode> Add<&SmartString<Mode>> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Add<&String> for SmartString<Mode>
impl<Mode: SmartStringMode> Add<&String> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Add<&str> for SmartString<Mode>
impl<Mode: SmartStringMode> Add<&str> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Add<String> for SmartString<Mode>
impl<Mode: SmartStringMode> Add<String> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Add for SmartString<Mode>
impl<Mode: SmartStringMode> Add for SmartString<Mode>
Source§impl<Mode: SmartStringMode> AsMut<str> for SmartString<Mode>
impl<Mode: SmartStringMode> AsMut<str> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> AsRef<[u8]> for SmartString<Mode>
impl<Mode: SmartStringMode> AsRef<[u8]> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> AsRef<str> for SmartString<Mode>
impl<Mode: SmartStringMode> AsRef<str> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Borrow<str> for SmartString<Mode>
impl<Mode: SmartStringMode> Borrow<str> for SmartString<Mode>
Source§impl<Mode: SmartStringMode> BorrowMut<str> for SmartString<Mode>
impl<Mode: SmartStringMode> BorrowMut<str> for SmartString<Mode>
Source§fn borrow_mut(&mut self) -> &mut str
fn borrow_mut(&mut self) -> &mut str
Source§impl<Mode: SmartStringMode> Clone for SmartString<Mode>
impl<Mode: SmartStringMode> Clone for SmartString<Mode>
Source§fn clone(&self) -> Self
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)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<Mode: SmartStringMode> Debug for SmartString<Mode>
impl<Mode: SmartStringMode> Debug for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Default for SmartString<Mode>
impl<Mode: SmartStringMode> Default for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Deref for SmartString<Mode>
impl<Mode: SmartStringMode> Deref for SmartString<Mode>
Source§impl<Mode: SmartStringMode> DerefMut for SmartString<Mode>
impl<Mode: SmartStringMode> DerefMut for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Display for SmartString<Mode>
impl<Mode: SmartStringMode> Display for SmartString<Mode>
Source§impl<Mode: SmartStringMode> Drop for SmartString<Mode>
impl<Mode: SmartStringMode> Drop for SmartString<Mode>
Source§impl<'a, Mode: SmartStringMode + 'a> Extend<&'a SmartString<Mode>> for SmartString<Mode>
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)
fn extend<I: IntoIterator<Item = &'a SmartString<Mode>>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, Mode: SmartStringMode> Extend<&'a String> for SmartString<Mode>
impl<'a, Mode: SmartStringMode> Extend<&'a String> for SmartString<Mode>
Source§fn extend<I: IntoIterator<Item = &'a String>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a String>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, Mode: SmartStringMode> Extend<&'a char> for SmartString<Mode>
impl<'a, Mode: SmartStringMode> Extend<&'a char> for SmartString<Mode>
Source§fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, Mode: SmartStringMode> Extend<&'a str> for SmartString<Mode>
impl<'a, Mode: SmartStringMode> Extend<&'a str> for SmartString<Mode>
Source§fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<Mode: SmartStringMode> Extend<SmartString<Mode>> for SmartString<Mode>
impl<Mode: SmartStringMode> Extend<SmartString<Mode>> for SmartString<Mode>
Source§fn extend<I: IntoIterator<Item = SmartString<Mode>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = SmartString<Mode>>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<Mode: SmartStringMode> Extend<String> for SmartString<Mode>
impl<Mode: SmartStringMode> Extend<String> for SmartString<Mode>
Source§fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<Mode: SmartStringMode> Extend<char> for SmartString<Mode>
impl<Mode: SmartStringMode> Extend<char> for SmartString<Mode>
Source§fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)