kstring/
lib.rs

1//! Key String: Optimized for map keys.
2//!
3//! # Background
4//!
5//! Considerations:
6//! - Large maps
7//! - Most keys live and drop without being used in any other way
8//! - Most keys are relatively small (single to double digit bytes)
9//! - Keys are immutable
10//! - Allow zero-cost abstractions between structs and maps (e.g. no allocating
11//!   when dealing with struct field names)
12//!
13//! Ramifications:
14//! - Inline small strings rather than going to the heap.
15//! - Preserve `&'static str` across strings (`KString`),
16//!   references (`KStringRef`), and lifetime abstractions (`KStringCow`) to avoid
17//!   allocating for struct field names.
18//! - Use `Box<str>` rather than `String` to use less memory.
19
20mod cow;
21mod inline;
22mod r#ref;
23mod string;
24
25pub use cow::*;
26pub use r#ref::*;
27pub use string::*;
28
29#[cfg(test)]
30mod test {
31    #[test]
32    fn test_size() {
33        println!(
34            "String: {}",
35            std::mem::size_of::<crate::string::StdString>()
36        );
37        println!(
38            "Box<str>: {}",
39            std::mem::size_of::<crate::string::OwnedStr>()
40        );
41        println!(
42            "Box<Box<str>>: {}",
43            std::mem::size_of::<Box<crate::string::OwnedStr>>()
44        );
45        println!("str: {}", std::mem::size_of::<&'static str>());
46        println!(
47            "Cow: {}",
48            std::mem::size_of::<std::borrow::Cow<'static, str>>()
49        );
50    }
51}