Expand description
A small-string-optimised immutable string type used throughout the value layer.
Strand backs string-shaped keys and values — Value::String, Object keys, TableName,
RecordIdKey::String — and trades the mutability of String for three complementary storage
strategies selected at construction time:
Inline— short strings (≤INLINE_CAPbytes) stored directly on the stack, with no heap allocation.Static— a&'static strwrapper for compile-time known values. Construction isconst, clone is a pointer copy, and drop is a no-op. Ideal for long literals (table names, reserved keywords, response keys) that would otherwise allocate. Build one withStrand::new_static.Boxed— dynamic long strings held in aBox<str>: one allocation per string, no atomic ops on construction or drop. Clone doesmalloc + memcpy, so reach forStrand::new_staticwhenever the value is known at compile time.
§Layout
Strand uses a custom 24-byte union layout. The first 16 bytes (on 64-bit) always form a
valid &str fat pointer for Static and Boxed strings. For Inline strings, the string
data is stored inline. The 24th byte (index 23) is used as a tag:
0..=23: The string isInline, and the tag is the length.254: The string isStatic.255: The string isBoxed.
This layout allows as_str() to be completely branchless, significantly improving the
performance of equality and ordering comparisons for all variants.
Structs§
- Strand
- Immutable string with inline small-string optimisation.
Constants§
- INLINE_
CAP - Maximum byte length of a string that can be stored inline.