[][src]Struct smartstring::SmartString

#[repr(C, align(8))]pub struct SmartString<Mode: SmartStringMode> { /* fields omitted */ }

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 LazyCompact.

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.

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)[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 a 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]

Filter out chars not matching a predicate.

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

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]

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.

impl<'_, Mode: SmartStringMode> Add<&'_ String> for SmartString<Mode>[src]

type Output = Self

The resulting type after applying the + operator.

impl<'_, Mode: SmartStringMode> Add<&'_ str> for SmartString<Mode>[src]

type Output = Self

The resulting type after applying the + operator.

impl<Mode: SmartStringMode> Add<SmartString<Mode>> for SmartString<Mode>[src]

type Output = Self

The resulting type after applying the + operator.

impl<Mode: SmartStringMode> Add<SmartString<Mode>> for String[src]

type Output = Self

The resulting type after applying the + operator.

impl<Mode: SmartStringMode> Add<String> for SmartString<Mode>[src]

type Output = Self

The resulting type after applying the + operator.

impl<Mode: SmartStringMode> Arbitrary for SmartString<Mode> where
    Mode: 'static, 
[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]

impl<Mode: SmartStringMode> Clone for SmartString<Mode>[src]

fn clone(&self) -> Self[src]

Clone a SmartString.

If the string is inlined, this is a Copy operation. Otherwise, String::clone() is invoked.

impl<Mode: SmartStringMode> Debug for SmartString<Mode>[src]

impl<Mode: SmartStringMode> Default for SmartString<Mode>[src]

impl<Mode: SmartStringMode> Deref for SmartString<Mode>[src]

type Target = str

The resulting type after dereferencing.

impl<Mode: SmartStringMode> DerefMut for SmartString<Mode>[src]

impl<'de, T: SmartStringMode> Deserialize<'de> for SmartString<T>[src]

impl<Mode: SmartStringMode> Display 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]

impl<'a, Mode: SmartStringMode> Extend<&'a String> for SmartString<Mode>[src]

impl<'a, Mode: SmartStringMode> Extend<&'a char> for SmartString<Mode>[src]

impl<'a, Mode: SmartStringMode> Extend<&'a str> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> Extend<SmartString<Mode>> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> Extend<String> for SmartString<Mode>[src]

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

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

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

impl<Mode: SmartStringMode> FromIterator<SmartString<Mode>> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> FromIterator<String> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> FromIterator<char> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> FromStr for SmartString<Mode>[src]

type Err = Infallible

The associated error which can be returned from parsing.

impl<Mode: SmartStringMode> Hash for SmartString<Mode>[src]

impl<Mode: SmartStringMode> Index<Range<usize>> for SmartString<Mode>[src]

type Output = str

The returned type after indexing.

impl<Mode: SmartStringMode> Index<RangeFrom<usize>> for SmartString<Mode>[src]

type Output = str

The returned type after indexing.

impl<Mode: SmartStringMode> Index<RangeFull> for SmartString<Mode>[src]

type Output = str

The returned type after indexing.

impl<Mode: SmartStringMode> Index<RangeInclusive<usize>> for SmartString<Mode>[src]

type Output = str

The returned type after indexing.

impl<Mode: SmartStringMode> Index<RangeTo<usize>> for SmartString<Mode>[src]

type Output = str

The returned type after indexing.

impl<Mode: SmartStringMode> Index<RangeToInclusive<usize>> for SmartString<Mode>[src]

type Output = str

The returned type after indexing.

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]

impl<Mode: SmartStringMode> IndexMut<RangeTo<usize>> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> IndexMut<RangeToInclusive<usize>> for SmartString<Mode>[src]

impl<Mode: SmartStringMode> Into<String> for SmartString<Mode>[src]

fn into(self) -> String[src]

Unwrap a boxed String, or copy an inline string into a new String.

impl<Mode: SmartStringMode> Ord for SmartString<Mode>[src]

impl<'_, Mode: SmartStringMode> PartialEq<SmartString<Mode>> for &'_ str[src]

impl<Mode: SmartStringMode> PartialEq<SmartString<Mode>> for str[src]

impl<Mode: SmartStringMode> PartialEq<SmartString<Mode>> for String[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]

impl<Mode: SmartStringMode> PartialOrd<str> for SmartString<Mode>[src]

impl<T: SmartStringMode> Serialize for SmartString<T>[src]

impl<Mode: SmartStringMode> Write for SmartString<Mode>[src]

Auto Trait Implementations

impl<Mode> RefUnwindSafe for SmartString<Mode> where
    <Mode as SmartStringMode>::InlineArray: RefUnwindSafe

impl<Mode> Send for SmartString<Mode> where
    <Mode as SmartStringMode>::InlineArray: Send

impl<Mode> Sync for SmartString<Mode> where
    <Mode as SmartStringMode>::InlineArray: Sync

impl<Mode> Unpin for SmartString<Mode> where
    <Mode as SmartStringMode>::InlineArray: Unpin

impl<Mode> UnwindSafe for SmartString<Mode> where
    <Mode as SmartStringMode>::InlineArray: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,