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