Type Alias AttrString
pub type AttrString = SmartString<LazyCompact>;
Expand description
A convenience alias for a [LazyCompact
] layout [SmartString
].
Just pretend it’s a String
!
Aliased Type§
struct AttrString { /* private fields */ }
Implementations
§impl SmartString<LazyCompact>
impl SmartString<LazyCompact>
pub const fn new_const() -> SmartString<LazyCompact>
pub const fn new_const() -> SmartString<LazyCompact>
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.
§impl<Mode> SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> SmartString<Mode>where
Mode: SmartStringMode,
pub fn new() -> SmartString<Mode>
pub fn new() -> SmartString<Mode>
Construct an empty string.
pub 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.
pub 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.
pub 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.
pub 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()
][SmartString::capacity] will
equal [len()
][SmartString::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.
pub 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.
pub 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.
pub 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.
pub 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.
pub fn split_off(&mut self, index: usize) -> SmartString<Mode>
pub fn split_off(&mut self, index: usize) -> SmartString<Mode>
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.
pub fn clear(&mut self)
pub fn clear(&mut self)
Clear the string.
This causes any memory reserved by the string to be immediately deallocated.
pub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Filter out char
s not matching a predicate.
pub 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.
pub 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 From<EntryClass> for AttrString
impl From<EntryClass> for AttrString
source§fn from(val: EntryClass) -> Self
fn from(val: EntryClass) -> Self
§impl<Mode> BorrowMut<str> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> BorrowMut<str> for SmartString<Mode>where
Mode: SmartStringMode,
§fn borrow_mut(&mut self) -> &mut str
fn borrow_mut(&mut self) -> &mut str
§impl<'de, T> Deserialize<'de> for SmartString<T>where
T: SmartStringMode,
impl<'de, T> Deserialize<'de> for SmartString<T>where
T: SmartStringMode,
§fn deserialize<D>(
deserializer: D,
) -> Result<SmartString<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<SmartString<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl<'a, Mode> Extend<&'a SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode + 'a,
impl<'a, Mode> Extend<&'a SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode + 'a,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a SmartString<Mode>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a SmartString<Mode>>,
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
)§impl<'a, Mode> Extend<&'a String> for SmartString<Mode>where
Mode: SmartStringMode,
impl<'a, Mode> Extend<&'a String> for SmartString<Mode>where
Mode: SmartStringMode,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a String>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a String>,
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
)§impl<'a, Mode> Extend<&'a char> for SmartString<Mode>where
Mode: SmartStringMode,
impl<'a, Mode> Extend<&'a char> for SmartString<Mode>where
Mode: SmartStringMode,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a char>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a char>,
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
)§impl<'a, Mode> Extend<&'a str> for SmartString<Mode>where
Mode: SmartStringMode,
impl<'a, Mode> Extend<&'a str> for SmartString<Mode>where
Mode: SmartStringMode,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a str>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a str>,
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
)§impl<Mode> Extend<SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> Extend<SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = SmartString<Mode>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = SmartString<Mode>>,
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
)§impl<Mode> Extend<String> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> Extend<String> for SmartString<Mode>where
Mode: SmartStringMode,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = String>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = String>,
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
)§impl<Mode> Extend<char> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> Extend<char> for SmartString<Mode>where
Mode: SmartStringMode,
§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = char>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = char>,
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
)§impl<'a, Mode> FromIterator<&'a SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode + 'a,
impl<'a, Mode> FromIterator<&'a SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode + 'a,
§fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = &'a SmartString<Mode>>,
fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = &'a SmartString<Mode>>,
§impl<'a, Mode> FromIterator<&'a String> for SmartString<Mode>where
Mode: SmartStringMode,
impl<'a, Mode> FromIterator<&'a String> for SmartString<Mode>where
Mode: SmartStringMode,
§fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = &'a String>,
fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = &'a String>,
§impl<'a, Mode> FromIterator<&'a str> for SmartString<Mode>where
Mode: SmartStringMode,
impl<'a, Mode> FromIterator<&'a str> for SmartString<Mode>where
Mode: SmartStringMode,
§fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = &'a str>,
fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = &'a str>,
§impl<Mode> FromIterator<SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> FromIterator<SmartString<Mode>> for SmartString<Mode>where
Mode: SmartStringMode,
§fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = SmartString<Mode>>,
fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = SmartString<Mode>>,
§impl<Mode> FromIterator<String> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> FromIterator<String> for SmartString<Mode>where
Mode: SmartStringMode,
§fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = String>,
fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = String>,
§impl<Mode> FromIterator<char> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> FromIterator<char> for SmartString<Mode>where
Mode: SmartStringMode,
§fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = char>,
fn from_iter<I>(iter: I) -> SmartString<Mode>where
I: IntoIterator<Item = char>,
§impl<Mode> Index<RangeInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> Index<RangeInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
§impl<Mode> Index<RangeToInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> Index<RangeToInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
§impl<Mode> IndexMut<RangeInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> IndexMut<RangeInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
§fn index_mut(
&mut self,
index: RangeInclusive<usize>,
) -> &mut <SmartString<Mode> as Index<RangeInclusive<usize>>>::Output
fn index_mut( &mut self, index: RangeInclusive<usize>, ) -> &mut <SmartString<Mode> as Index<RangeInclusive<usize>>>::Output
container[index]
) operation. Read more§impl<Mode> IndexMut<RangeToInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
impl<Mode> IndexMut<RangeToInclusive<usize>> for SmartString<Mode>where
Mode: SmartStringMode,
§fn index_mut(
&mut self,
index: RangeToInclusive<usize>,
) -> &mut <SmartString<Mode> as Index<RangeToInclusive<usize>>>::Output
fn index_mut( &mut self, index: RangeToInclusive<usize>, ) -> &mut <SmartString<Mode> as Index<RangeToInclusive<usize>>>::Output
container[index]
) operation. Read more