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: a compact “stack” of string slices backed by a single byte buffer.

§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::StrStack;
pub use crate::str_stack::StrStackIter;

Modules§

pascal_string
smart_string
str_stack

Traits§

DisplayExt