Skip to main content

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//! The implementation automatically uses SIMD for strings >= 16 bytes and falls back to scalar operations
23//! for smaller inputs or when SIMD is not available.
24//!
25//! To enable SIMD acceleration:
26//! ```toml
27//! [dependencies]
28//! cheetah-string = { version = "2.0.0", features = ["simd"] }  
29//! ```
30//!
31//! # Examples
32//!
33//! Basic usage:
34//! ```rust
35//! use cheetah_string::CheetahString;
36//!
37//!
38//!  let s = CheetahString::from("Hello, world!");
39//!
40//!  let s2:&'static str = "Hello, world!";
41//!  let s3 = CheetahString::from_static_str(s2);
42//!
43//!  let s4 = CheetahString::new();
44//!
45//! ```
46//!
47//! Using accelerated search operations:
48//! ```rust
49//! use cheetah_string::CheetahString;
50//!
51//! let url = CheetahString::from("https://api.example.com/v1/users");
52//!
53//! // Substring search uses memchr/memmem by default.
54//! if url.starts_with("https://") {
55//!     println!("Secure connection");
56//! }
57//!
58//! if url.contains("api") {
59//!     println!("API endpoint");
60//! }
61//! ```
62//!
63extern crate alloc;
64
65mod builder;
66mod cheetah_str;
67mod cheetah_string;
68mod error;
69mod search;
70
71#[cfg(feature = "bytes")]
72#[path = "bytes.rs"]
73mod cheetah_bytes;
74
75#[cfg(feature = "serde")]
76mod serde;
77
78#[cfg(all(feature = "simd", target_arch = "x86_64"))]
79mod simd;
80
81#[cfg(feature = "experimental-packed")]
82pub mod packed;
83
84#[cfg(feature = "bytes")]
85pub use cheetah_bytes::CheetahBytes;
86
87pub use builder::CheetahBuilder;
88pub use cheetah_str::CheetahStr;
89pub use cheetah_string::{CheetahString, SplitPattern, SplitStr, SplitWrapper, StrPattern};
90pub use error::{Error, Result};
91pub use search::CheetahFinder;