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 strings, dynamic strings, and byte arrays.
4//! It is usable in both `std` and `no_std` environments. Additionally, CheetahString supports serde for serialization and deserialization.
5//! CheetahString also supports the `bytes` feature, allowing conversion to the `bytes::Bytes` type.
6//! This reduces memory allocations during cloning, enhancing performance.
7//!
8//! # SIMD Acceleration
9//!
10//! When compiled with the `simd` feature flag, CheetahString uses SIMD (Single Instruction, Multiple Data)
11//! instructions to accelerate string matching operations on x86_64 platforms with SSE2 support.
12//! SIMD acceleration is applied to:
13//! - `starts_with()` - Pattern prefix matching
14//! - `ends_with()` - Pattern suffix matching
15//! - `contains()` / `find()` - Substring search
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.0.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 SIMD-accelerated operations (when `simd` feature is enabled):
44//! ```rust
45//! use cheetah_string::CheetahString;
46//!
47//! let url = CheetahString::from("https://api.example.com/v1/users");
48//!
49//! // These operations use SIMD when the pattern is >= 16 bytes
50//! if url.starts_with("https://") {
51//! println!("Secure connection");
52//! }
53//!
54//! if url.contains("api") {
55//! println!("API endpoint");
56//! }
57//! ```
58//!
59mod cheetah_string;
60mod error;
61
62#[cfg(feature = "serde")]
63mod serde;
64
65#[cfg(all(feature = "simd", target_arch = "x86_64"))]
66mod simd;
67
68pub use cheetah_string::{CheetahString, SplitPattern, SplitStr, SplitWrapper, StrPattern};
69pub use error::{Error, Result};