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//! The `bytes` feature exposes `CheetahBytes` for byte-oriented data.
6//! It minimizes allocations across small, shared, and builder-oriented string workloads.
7//! The `from_string_owned` and `from_string_shared` constructors make owned
8//! mutation and clone-cheap sharing policies explicit.
9//! Substring search uses `memchr`/`memmem` by default.
10//!
11//! # SIMD Acceleration
12//!
13//! When compiled with the `simd` feature flag, CheetahString uses SIMD (Single Instruction, Multiple Data)
14//! instructions to accelerate selected byte comparisons on x86_64 platforms with SSE2 support.
15//! SIMD acceleration is applied to:
16//! - `starts_with()` - Pattern prefix matching
17//! - `ends_with()` - Pattern suffix matching
18//! - Equality comparisons (`==`, `!=`)
19//!
20//! The implementation automatically uses SIMD for strings >= 16 bytes and falls back to scalar operations
21//! for smaller inputs or when SIMD is not available.
22//!
23//! To enable SIMD acceleration:
24//! ```toml
25//! [dependencies]
26//! cheetah-string = { version = "1.2.0", features = ["simd"] }  
27//! ```
28//!
29//! # Examples
30//!
31//! Basic usage:
32//! ```rust
33//! use cheetah_string::CheetahString;
34//!
35//!
36//!  let s = CheetahString::from("Hello, world!");
37//!
38//!  let s2:&'static str = "Hello, world!";
39//!  let s3 = CheetahString::from_static_str(s2);
40//!
41//!  let s4 = CheetahString::new();
42//!
43//! ```
44//!
45//! Using accelerated search operations:
46//! ```rust
47//! use cheetah_string::CheetahString;
48//!
49//! let url = CheetahString::from("https://api.example.com/v1/users");
50//!
51//! // Substring search uses memchr/memmem by default.
52//! if url.starts_with("https://") {
53//!     println!("Secure connection");
54//! }
55//!
56//! if url.contains("api") {
57//!     println!("API endpoint");
58//! }
59//! ```
60//!
61extern crate alloc;
62
63mod cheetah_string;
64mod error;
65mod search;
66
67#[cfg(feature = "bytes")]
68#[path = "bytes.rs"]
69mod cheetah_bytes;
70
71#[cfg(feature = "serde")]
72mod serde;
73
74#[cfg(all(feature = "simd", target_arch = "x86_64"))]
75mod simd;
76
77#[cfg(feature = "experimental-packed")]
78pub mod packed;
79
80#[cfg(feature = "bytes")]
81pub use cheetah_bytes::CheetahBytes;
82
83pub use cheetah_string::{CheetahString, SplitPattern, SplitStr, SplitWrapper, StrPattern};
84pub use error::{Error, Result};
85pub use search::CheetahFinder;