fast_str/lib.rs
1//! FastStr: A flexible, easy-to-use, immutable, efficient `String` replacement for Rust.
2//!
3//! ## What is FastStr
4//! [FastStr] is a read-only string wrapper. You can think of it as an ownership `&str` type.
5//! FastStr uses three variants of `&'static str`, `Arc<String>` and `StackString`, and automatically selects the best storage method;
6//! And optimized string cloning and string comparison.
7//!
8//! ## What Is It For?
9//! [FastStr] is better than String as long as it is not often necessary to modify strings and connect strings.
10//!
11//! ## How To Use It?
12//! String constants are easily wrapped into the unified [FastStr] type. For other string types, different types of storage will be automatically selected.
13//! ```
14//! use fast_str::FastStr;
15//! // compile-time constants
16//! const EMPTY_STR: FastStr = FastStr::new();
17//! const STATIC_STR: FastStr = FastStr::from_static("💙❤");
18//!
19//! let str1: FastStr = "🍷 wink".into();
20//! // String storage is used in 32-bit machines,
21//! // and stack memory is used in 64 bit machines to store strings
22//! let str2 = FastStr::from_ref("😆 Happy");
23//!
24//! // You can use the operator '+' to connect strings.
25//! let str3: FastStr = str1 + str2;
26//!
27//! // O(1) Clone() of time complexity.
28//! let str4: FastStr = str3.clone();
29//!
30//! // You can use String as the storage variant of FastStr,
31//! // and when FastStr has the sole ownership of the String variant,
32//! // no performance consumption is converted to the String type.
33//! let from_string = FastStr::from_string(String::from("hello world"));
34//! let from_faststr = String::from(from_string);
35//! ```
36//!
37//! ## Feature Flags
38//!
39//! `fast-str` comes with optional support for the following crates through Cargo
40//! feature flags. You can enable them in your `Cargo.toml` file like this:
41//!
42//! ```no_compile
43//! [dependencies]
44//! fast-str = { version = "*", features = ["rocket", "serde"] }
45//! ```
46//!
47//! | Feature | Description |
48//! | ------- | ----------- |
49//! | [`arbitrary`](https://crates.io/crates/arbitrary) | [`Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html) implementation for [`FastStr`]. |
50//! | [`actix-web`](https://crates.io/crates/actix-web) | [`Responder`](https://docs.rs/actix-web/latest/actix_web/trait.Responder.html) implementation for [`FastStr`]. |
51//! | [`serde`](https://crates.io/crates/serde) | [`Serialize`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html) and [`Deserialize`](https://docs.rs/serde/latest/serde/trait.Deserialize.html) implementations for [`FastStr`]. |
52//! | [`diffus`](https://crates.io/crates/diffus) | [`Same`](https://docs.rs/diffus/0.10.0/diffus/trait.Same.html) and [`Deserialize`](https://docs.rs/diffus/0.10.0/diffus/trait.Diffable.html) implementations for [`FastStr`]. |
53mod backend;
54mod iter;
55mod normal;
56mod pattern;
57mod stack;
58
59pub use self::backend::FastStr;