Crate tiny_str

Source
Expand description

Tiny string

A string that can store a small amount of bytes on the stack.

This struct provides a string-like API, but performs SSO (Small String Optimization) This means that a TinyString<N> stores up to N bytes on the stack. If the string grows bigger than that, it moves the contents to the heap.

§Example

use tiny_str::TinyString;

let mut s = TinyString::<10>::new();

for (i, c) in (b'0'..=b'9').enumerate() {
    s.push(c as char);
    assert_eq!(s.len(), i + 1);
}

// Up to this point, no heap allocations are needed.
// The string is stored on the stack.

s.push_str("abc"); // This moves the string to the heap

assert_eq!(&s[..], "0123456789abc")

§Memory layout

TinyString is based on TinyVec, just like alloc::string::String if based on alloc::vec::Vec.

You can read the tiny_vec crate documentation to learn about the internal representation of the data.

Modules§

drain
drain implementation
iter
Iterators for the TinyString

Structs§

TinyString
A string that can store a small amount of bytes on the stack.