Skip to main content

Crate smart_string

Crate smart_string 

Source
Expand description

smart-string is a collection of small string primitives:

  • PascalString: fixed-capacity UTF-8 string stored inline (stack / in-place).
  • SmartString: stack-or-heap string that promotes to heap when needed.
  • StrStack: mutable builder for a compact list of string segments in a single byte buffer.
  • StrList: frozen (immutable) string list with no excess capacity.
  • StrListRef: borrowed read-only view over string list data (zero-copy).

§Notes

  • SmartString promotion (stack → heap) can happen implicitly during mutation when capacity is exceeded.
  • Demotion (heap → stack) is explicit and must be requested via SmartString::try_into_stack.

§Safety & invariants

This crate contains a small amount of unsafe code used to project internal UTF‑8 byte buffers as &str / &mut str without repeated validation and bounds checks.

Soundness relies on internal invariants:

  • PascalString: len <= CAPACITY and data[..len] is always valid UTF‑8.
  • StrStack: data is always valid UTF‑8 and ends stores valid UTF‑8 segment boundaries within data.

See also: docs/parity.api.md for the “std String parity” checklist and compatibility notes.

  • MSRV (default features): Rust 1.59.0.
    • Motivation: SmartString’s public API uses a default const generic parameter (SmartString<const N: usize = DEFAULT_CAPACITY>), which requires newer compilers.
    • Note: MSRV is a rustc guarantee for this crate. Without a committed Cargo.lock, transitive dependency MSRVs can drift over time; our CI runs an MSRV job to detect such drift.

Re-exports§

pub use crate::pascal_string::PascalString;
pub use crate::smart_string::IntoChars;
pub use crate::smart_string::SmartString;
pub use crate::smart_string::Utf16DecodeError;
pub use crate::str_stack::Checkpoint;
pub use crate::str_stack::StrList;
pub use crate::str_stack::StrListIter;
pub use crate::str_stack::StrListRef;
pub use crate::str_stack::StrListValidationError;
pub use crate::str_stack::StrStack;
pub use crate::str_stack::StrStackIter;
pub use crate::str_stack::StrStackOverflow;

Modules§

pascal_string
smart_string
str_stack
A compact string collection backed by a single contiguous byte buffer.

Traits§

DisplayExt