Struct smartstring::SmartString[][src]

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

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

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.

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.

Construct an empty string.

Return the length in bytes of the string.

Note that this may differ from the length in chars.

Test whether the string is empty.

Test whether the string is currently inlined.

Get a reference to the string as a string slice.

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

Push a character to the end of the string.

Copy a string slice onto the end of the string.

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.

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.

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.

Pop a char off the end of the string.

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.

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.

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.

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.

Clear the string.

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

Filter out chars not matching a predicate.

Construct a draining iterator over a given range.

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

Replaces a range with the contents of a string slice.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Generate an arbitrary value of Self from the given unstructured data. Read more

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more

Generate an iterator of derived values which are “smaller” than the original self instance. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Clone a SmartString.

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

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

The returned type after indexing.

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

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

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

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

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

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

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

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.