cheetah_string/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2
3//! No more relying solely on the standard library's String! CheetahString is a versatile string type that can store static and dynamic strings.
4//! It is usable in both `std` and `no_std` environments. Additionally, CheetahString supports serde for serialization and deserialization.
5//! `CheetahStr` is available for immutable clone-cheap string values, and
6//! `CheetahBuilder` is available for append-heavy construction.
7//! The `bytes` feature exposes `CheetahBytes` for byte-oriented data.
8//! It minimizes allocations across small, shared, and builder-oriented string workloads.
9//! `from_string` preserves owned storage for mutable string workflows.
10//! Use `CheetahStr` for clone-cheap immutable values.
11//! Substring search uses `memchr`/`memmem` by default.
12//!
13//! # SIMD Acceleration
14//!
15//! When compiled with the `simd` feature flag, CheetahString uses SIMD (Single Instruction, Multiple Data)
16//! instructions to accelerate selected byte comparisons on x86_64 platforms with SSE2 support.
17//! SIMD acceleration is applied to:
18//! - `starts_with()` - Pattern prefix matching
19//! - `ends_with()` - Pattern suffix matching
20//! - Equality comparisons (`==`, `!=`)
21//!
22//! Substring search through `find()` and `contains()` continues to use
23//! `memchr`/`memmem`, which is the stable default search backend.
24//!
25//! The implementation automatically uses SIMD for strings >= 16 bytes and falls back to scalar operations
26//! for smaller inputs or when SIMD is not available.
27//!
28//! To enable SIMD acceleration:
29//! ```toml
30//! [dependencies]
31//! cheetah-string = { version = "2.1.0", features = ["simd"] }
32//! ```
33//!
34//! # Examples
35//!
36//! Basic usage:
37//! ```rust
38//! use cheetah_string::CheetahString;
39//!
40//!
41//! let s = CheetahString::from("Hello, world!");
42//!
43//! let s2:&'static str = "Hello, world!";
44//! let s3 = CheetahString::from_static_str(s2);
45//!
46//! let s4 = CheetahString::new();
47//!
48//! ```
49//!
50//! Using search operations:
51//! ```rust
52//! use cheetah_string::CheetahString;
53//!
54//! let url = CheetahString::from("https://api.example.com/v1/users");
55//!
56//! // Substring search uses memchr/memmem by default.
57//! if url.starts_with("https://") {
58//! println!("Secure connection");
59//! }
60//!
61//! if url.contains("api") {
62//! println!("API endpoint");
63//! }
64//! ```
65//!
66extern crate alloc;
67
68mod builder;
69mod cheetah_str;
70mod cheetah_string;
71mod error;
72mod inline;
73mod search;
74
75#[cfg(feature = "bytes")]
76#[path = "bytes.rs"]
77mod cheetah_bytes;
78
79#[cfg(feature = "serde")]
80mod serde;
81
82#[cfg(all(feature = "simd", target_arch = "x86_64"))]
83mod simd;
84
85#[cfg(feature = "experimental-packed")]
86pub mod packed;
87
88#[cfg(feature = "bytes")]
89pub use cheetah_bytes::CheetahBytes;
90
91pub use builder::CheetahBuilder;
92pub use cheetah_str::CheetahStr;
93pub use cheetah_string::{CheetahString, SplitPattern, SplitStr, SplitWrapper, StrPattern};
94pub use error::{Error, Result};
95pub use search::CheetahFinder;