[][src]Struct smartstring::Prefixed

pub struct Prefixed;

A string representation that always keeps an inline prefix.

This layout is optimised for use cases with frequent comparisons of long strings using Ord or Eq.

This looks similar to Compact when inlined, except it has one pointer's length's worth of extra space - 31 bytes in total on 64-bit architectures, 15 on 32-bit. The boxed variant copies up to FRAGMENT_SIZE bytes of the string into its local representation, in order to avoid dereferencing as much as possible when checking for equality and ordering, and uses the same byte as its inline version to store the discriminant bit plus the length of the fragment (which may be below FRAGMENT_SIZE if it contains multibyte UTF-8 characters).

When To Use This?

This comes with an overhead on many operations, and on top of that, the Ord implementation is necessarily more complex because it's dealing with multiple UTF-8 slices, and comparing them isn't nontrivial. Especially, when comparing the prefix against something with an unknown amount of chars, or where you don't know exactly where the relevant char boundary is up front, we have to track the char count as we compare, which is considerably slower than a simple memcmp. For this reason, always compare SmartStrings to other SmartStrings, not to string slices, because they track their prefix char counts and can optimise for when they're identical.

This performs best when the prefix is likely to be able to quickly decide non-equivalence, and when the full comparison is likely to have to do enough work to compensate for the extra overhead of the prefix check. In other words, it outperforms regular strings and Compact layout SmartStrings when you have long keys that rarely share a common prefix. If your keys tend to be short, or if common prefixes are the norm, you're much better off using Compact. As a rule, when in doubt: benchmark.

Trait Implementations

impl Debug for Prefixed[src]

impl SmartStringMode for Prefixed[src]

type BoxedString = FragmentString

The boxed string type for this layout.

type InlineArray = [u8; 15]

The inline string type for this layout.

Auto Trait Implementations

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> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[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.