[−][src]Struct smartstring::SmartString
A smart string.
This wraps one of two string types: an inline string or a boxed string. Conversion between the two happens opportunistically and transparently.
It takes a layout as its type argument: one of Compact or Prefixed.
It mimics the interface of String except where behaviour cannot
be guaranteed to stay consistent between its boxed and inline states. This means
you still have capacity() and shrink_to_fit(), relating to state that only
really exists in the boxed variant, because the inline variant can still give
sensible behaviour for these operations, but with_capacity(), reserve() etc are
absent, because they would have no effect on inline strings and the requested
state changes wouldn't carry over if the inline string is promoted to a boxed
one - not without also storing that state in the inline representation, which
would waste precious bytes for inline string data.
Implementations
impl<Mode: SmartStringMode> SmartString<Mode>[src]
pub fn new() -> Self[src]
Construct an empty string.
pub fn len(&self) -> usize[src]
Return the length in bytes of the string.
Note that this may differ from the length in chars.
pub fn is_empty(&self) -> bool[src]
Test whether the string is empty.
pub fn is_inline(&self) -> bool[src]
Test whether the string is currently inlined.
pub fn as_str(&self) -> &str[src]
Get a reference to the string as a string slice.
pub fn as_mut_str(&mut self) -> &mut str[src]
Get a reference to the string as a mutable string slice.
pub fn push(&mut self, ch: char)[src]
Push a character to the end of the string.
pub fn push_str(&mut self, string: &str)[src]
Copy a string slice onto the end of the string.
pub fn capacity(&self) -> usize[src]
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 SmartStringMode::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)[src]
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.
pub fn truncate(&mut self, new_len: usize)[src]
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 an UTF-8 character boundary, this method panics.
pub fn pop(&mut self) -> Option<char>[src]
Pop a char off the end of the string.
pub fn remove(&mut self, index: usize) -> char[src]
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)[src]
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)[src]
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) -> Self[src]
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)[src]
Clear the string.
This causes any memory reserved by the string to be immediately deallocated.
pub fn retain<F>(&mut self, f: F) where
F: FnMut(char) -> bool, [src]
F: FnMut(char) -> bool,
Filter out chars not matching a predicate.
pub fn drain<R>(&mut self, range: R) -> Drain<Mode> where
R: RangeBounds<usize>, [src]
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.
pub fn replace_range<R>(&mut self, range: R, replace_with: &str) where
R: RangeBounds<usize>, [src]
R: RangeBounds<usize>,
Replaces a range with the contents of a string slice.
Trait Implementations
impl<'_, Mode: SmartStringMode> Add<&'_ SmartString<Mode>> for SmartString<Mode>[src]
type Output = Self
The resulting type after applying the + operator.
fn add(self, rhs: &Self) -> Self::Output[src]
impl<'_, Mode: SmartStringMode> Add<&'_ String> for SmartString<Mode>[src]
type Output = Self
The resulting type after applying the + operator.
fn add(self, rhs: &String) -> Self::Output[src]
impl<'_, Mode: SmartStringMode> Add<&'_ str> for SmartString<Mode>[src]
type Output = Self
The resulting type after applying the + operator.
fn add(self, rhs: &str) -> Self::Output[src]
impl<Mode: SmartStringMode> Add<SmartString<Mode>> for SmartString<Mode>[src]
type Output = Self
The resulting type after applying the + operator.
fn add(self, rhs: Self) -> Self::Output[src]
impl<Mode: SmartStringMode> Add<SmartString<Mode>> for String[src]
type Output = Self
The resulting type after applying the + operator.
fn add(self, rhs: SmartString<Mode>) -> Self::Output[src]
impl<Mode: SmartStringMode> Add<String> for SmartString<Mode>[src]
type Output = Self
The resulting type after applying the + operator.
fn add(self, rhs: String) -> Self::Output[src]
impl<Mode: SmartStringMode> AsMut<str> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> AsRef<[u8]> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> AsRef<str> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Borrow<str> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> BorrowMut<str> for SmartString<Mode>[src]
fn borrow_mut(&mut self) -> &mut str[src]
impl<Mode: SmartStringMode> Clone for SmartString<Mode>[src]
fn clone(&self) -> Self[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<Mode: SmartStringMode> Debug for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Default for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Deref for SmartString<Mode>[src]
impl<Mode: SmartStringMode> DerefMut for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Drop for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Eq for SmartString<Mode>[src]
impl<'a, Mode: SmartStringMode + 'a> Extend<&'a SmartString<Mode>> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = &'a SmartString<Mode>>>(&mut self, iter: I)[src]
impl<'a, Mode: SmartStringMode> Extend<&'a String> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = &'a String>>(&mut self, iter: I)[src]
impl<'a, Mode: SmartStringMode> Extend<&'a char> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)[src]
impl<'a, Mode: SmartStringMode> Extend<&'a str> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)[src]
impl<Mode: SmartStringMode> Extend<SmartString<Mode>> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = SmartString<Mode>>>(&mut self, iter: I)[src]
impl<Mode: SmartStringMode> Extend<String> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)[src]
impl<Mode: SmartStringMode> Extend<char> for SmartString<Mode>[src]
fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)[src]
impl<'_, Mode: SmartStringMode> From<&'_ String> for SmartString<Mode>[src]
impl<'_, Mode: SmartStringMode> From<&'_ str> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> From<Box<str>> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> From<String> for SmartString<Mode>[src]
impl<'a, Mode: SmartStringMode + 'a> FromIterator<&'a SmartString<Mode>> for SmartString<Mode>[src]
fn from_iter<I: IntoIterator<Item = &'a Self>>(iter: I) -> Self[src]
impl<'a, Mode: SmartStringMode> FromIterator<&'a String> for SmartString<Mode>[src]
fn from_iter<I: IntoIterator<Item = &'a String>>(iter: I) -> Self[src]
impl<'a, Mode: SmartStringMode> FromIterator<&'a str> for SmartString<Mode>[src]
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> Self[src]
impl<Mode: SmartStringMode> FromIterator<SmartString<Mode>> for SmartString<Mode>[src]
fn from_iter<I: IntoIterator<Item = Self>>(iter: I) -> Self[src]
impl<Mode: SmartStringMode> FromIterator<String> for SmartString<Mode>[src]
fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> Self[src]
impl<Mode: SmartStringMode> FromStr for SmartString<Mode>[src]
type Err = Infallible
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>[src]
impl<Mode: SmartStringMode> Hash for SmartString<Mode>[src]
fn hash<H: Hasher>(&self, state: &mut H)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl<Mode: SmartStringMode> Index<Range<usize>> for SmartString<Mode>[src]
type Output = str
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &Self::Output[src]
impl<Mode: SmartStringMode> Index<RangeFrom<usize>> for SmartString<Mode>[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &Self::Output[src]
impl<Mode: SmartStringMode> Index<RangeFull> for SmartString<Mode>[src]
type Output = str
The returned type after indexing.
fn index(&self, _index: RangeFull) -> &Self::Output[src]
impl<Mode: SmartStringMode> Index<RangeInclusive<usize>> for SmartString<Mode>[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeInclusive<usize>) -> &Self::Output[src]
impl<Mode: SmartStringMode> Index<RangeTo<usize>> for SmartString<Mode>[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &Self::Output[src]
impl<Mode: SmartStringMode> Index<RangeToInclusive<usize>> for SmartString<Mode>[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output[src]
impl<Mode: SmartStringMode> IndexMut<Range<usize>> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> IndexMut<RangeFrom<usize>> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> IndexMut<RangeFull> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> IndexMut<RangeInclusive<usize>> for SmartString<Mode>[src]
fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output[src]
impl<Mode: SmartStringMode> IndexMut<RangeTo<usize>> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> IndexMut<RangeToInclusive<usize>> for SmartString<Mode>[src]
fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output[src]
impl<Mode: SmartStringMode> Into<String> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Ord for SmartString<Mode>[src]
fn cmp(&self, other: &Self) -> Ordering[src]
#[must_use]fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self[src]
impl<'_, Mode: SmartStringMode> PartialEq<SmartString<Mode>> for &'_ str[src]
fn eq(&self, other: &SmartString<Mode>) -> bool[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl<Mode: SmartStringMode> PartialEq<SmartString<Mode>> for str[src]
fn eq(&self, other: &SmartString<Mode>) -> bool[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl<Mode: SmartStringMode> PartialEq<SmartString<Mode>> for String[src]
fn eq(&self, other: &SmartString<Mode>) -> bool[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl<Mode: SmartStringMode> PartialEq<SmartString<Mode>> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> PartialEq<String> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> PartialEq<str> for SmartString<Mode>[src]
impl<Mode: SmartStringMode> PartialOrd<SmartString<Mode>> for SmartString<Mode>[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool1.0.0[src]
impl<Mode: SmartStringMode> PartialOrd<str> for SmartString<Mode>[src]
fn partial_cmp(&self, other: &str) -> Option<Ordering>[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool1.0.0[src]
impl<Mode: SmartStringMode> ToString for SmartString<Mode>[src]
impl<Mode: SmartStringMode> Write for SmartString<Mode>[src]
Auto Trait Implementations
impl<Mode> RefUnwindSafe for SmartString<Mode> where
<Mode as SmartStringMode>::InlineArray: RefUnwindSafe,
<Mode as SmartStringMode>::InlineArray: RefUnwindSafe,
impl<Mode> Send for SmartString<Mode> where
<Mode as SmartStringMode>::InlineArray: Send,
<Mode as SmartStringMode>::InlineArray: Send,
impl<Mode> Sync for SmartString<Mode> where
<Mode as SmartStringMode>::InlineArray: Sync,
<Mode as SmartStringMode>::InlineArray: Sync,
impl<Mode> Unpin for SmartString<Mode> where
<Mode as SmartStringMode>::InlineArray: Unpin,
<Mode as SmartStringMode>::InlineArray: Unpin,
impl<Mode> UnwindSafe for SmartString<Mode> where
<Mode as SmartStringMode>::InlineArray: UnwindSafe,
<Mode as SmartStringMode>::InlineArray: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,