nu_utils/strings/
mod.rs

1//! String utility types with specific semantics.
2//!
3//! This module provides additional string types optimized for certain use-cases, offering
4//! alternatives to standard [`String`] or [`&str`](str) when specific performance characteristics
5//! are desired.
6//!
7//! The pipeline-based, functional programming model, we use, leads to frequent string operations
8//! that involve immutability and often copying.
9//! These specialized string types can provide performance and memory benefits for these cases.
10//!
11//! ## Choosing a String Type: `SharedString` vs. `UniqueString`
12//!
13//! ### Use [`SharedString`] when:
14//!
15//! `SharedString` is an owned, immutable string type optimized for **frequent cloning and sharing**.
16//! Cloning it is very inexpensive (a pointer copy and atomic reference count increment), avoiding
17//! deep copies of the string data.
18//! It also benefits from Small String Optimization (SSO) and static string re-use.
19//!
20//! **Ideal for:** Strings that need to be duplicated or passed by value frequently across
21//! pipeline stages or within complex data structures, where many references to the same string
22//! data are expected.
23//!
24//! ### Use [`UniqueString`] when:
25//!
26//! `UniqueString` is an owned, immutable string type optimized for
27//! **strings that are primarily unique** or rarely cloned.
28//! Cloning a `UniqueString` always involves copying the underlying string data.
29//! Its advantage lies in avoiding the overhead of atomic reference counting.
30//! It also benefits from Small String Optimization (SSO) and static string re-use.
31//!
32//! **Ideal for:** Strings that are created and consumed locally, or represent unique identifiers
33//! that are not expected to be duplicated across many ownership boundaries.
34//! When the cost of copying upon infrequent clones is acceptable.
35
36mod shared;
37mod unique;
38
39pub use shared::SharedString;
40pub use unique::UniqueString;