Skip to main content

Crate cheetah_string

Crate cheetah_string 

Source
Expand description

An immutable, clone-cheap UTF-8 value for latency-sensitive systems.

CheetahString has one constructor-independent value contract:

  • explicit static values borrow their &'static str;
  • other values up to 23 bytes are stored inline;
  • other long values use a shared Arc<str> backing.

Long clones are bounded O(1) and allocate zero times. Append-heavy construction belongs to CheetahBuilder; call CheetahBuilder::finish to freeze the value or CheetahBuilder::into_string when mutation or spare capacity must continue. from_string freezes its input and does not retain a mutable String representation. Long Arc<str> inputs can be adopted without allocation through CheetahString::from_arc_str.

The crate supports no_std + alloc. Optional serde integration preserves the text contract, while the bytes feature exposes CheetahBytes for byte-oriented data. Byte-to-text conversion validates and copies; only bytes::Bytes <-> CheetahBytes is zero-copy.

§Split capability

CheetahString::split_char returns a double-ended standard iterator. CheetahString::split_str is forward-only, so unsupported reverse iteration fails at compile time rather than panicking at runtime.

§Search and experimental SIMD

Stable builds delegate equality, prefix, and suffix comparisons to the standard slice/str implementations so the compiler and standard library select the best portable strategy. The experimental-simd feature exposes an x86_64 SSE2 experiment for controlled benchmarking only. The deprecated simd feature remains a 3.x compatibility alias.

Substring search through find() and contains() continues to use memchr/memmem, which is the stable default search backend.

§Retired experimental features

The former experimental-packed flag is a compatibility no-op. Its v1 public type was removed because integer-to-pointer reconstruction did not satisfy Rust’s strict-provenance model.

use cheetah_string::packed::PackedCheetahString;

To opt into the isolated experiment:

[dependencies]
cheetah-string = { version = "3.1.0", features = ["experimental-simd"] }

§Example

use cheetah_string::{CheetahBuilder, CheetahString};

let topic = CheetahString::from_static_str("orders");
assert!(topic.starts_with("ord"));

let mut builder = CheetahBuilder::with_capacity(32);
builder.push_str(topic.as_str());
builder.push('@');
builder.push_str("group-a");

let route = builder.finish();
assert_eq!(route, "orders@group-a");

Structs§

CheetahBuilder
Append-heavy builder for constructing Cheetah string values.
CheetahFinder
Reusable substring finder for repeated searches with the same needle.
CheetahString
Immutable string value with inline, static, or shared backing.
SplitStr
Helper struct for splitting strings by a string pattern.

Enums§

Error
Compatibility error type for range operations and explicit conversions.

Traits§

SplitPattern
A compatibility pattern whose iterator type exposes its capabilities.
StrPattern
A sealed pattern accepted by text query methods.

Type Aliases§

CheetahStrDeprecated
Deprecated v3 compatibility name for CheetahString.
Result
Result type for CheetahString operations.