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 fn
s 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 fn
s to stabilise, and will be deprecated
once this happens.
Return the length in bytes of the string.
Note that this may differ from the length in char
s.
Get a reference to the string as a mutable string slice.
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.
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 char
s 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 char
s.
Replaces a range with the contents of a string slice.
Trait Implementations
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
Deserialize this value from the given Serde deserializer. Read more
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
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
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. 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
Creates a value from an iterator. 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 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
Writes a string slice into this writer, returning whether the write succeeded. Read more
Auto Trait Implementations
impl<Mode> RefUnwindSafe for SmartString<Mode> where
Mode: RefUnwindSafe,
impl<Mode> Send for SmartString<Mode> where
Mode: Send,
impl<Mode> Sync for SmartString<Mode> where
Mode: Sync,
impl<Mode> Unpin for SmartString<Mode> where
Mode: Unpin,
impl<Mode> UnwindSafe for SmartString<Mode> where
Mode: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more