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
SmartStringpromotion (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 <= CAPACITYanddata[..len]is always valid UTF‑8.StrStack:datais always valid UTF‑8 andendsstores valid UTF‑8 segment boundaries withindata.
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
rustcguarantee for this crate. Without a committedCargo.lock, transitive dependency MSRVs can drift over time; our CI runs an MSRV job to detect such drift.
- Motivation:
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;