Expand description
Key String: Optimized for map keys.
§Examples
String creation
// Explicit
let literal = kstring::KString::from_static("literal");
// Implicit
let literal = kstring::KString::from("literal");
// Explicit
let inline = kstring::KString::try_inline("stack").unwrap();
let inline = kstring::KString::from_ref("stack");
let formatted: kstring::KStringCow = format!("Hello {} and {}", literal, inline).into();§Background
Considerations:
- Large maps
- Most keys live and drop without being used in any other way
- Most keys are relatively small (single to double digit bytes)
- Keys are immutable
- Allow zero-cost abstractions between structs and maps (e.g. no allocating when dealing with struct field names)
Ramifications:
- Inline small strings rather than going to the heap.
- Preserve
&'static stracross strings (KString), references (KStringRef), and lifetime abstractions (KStringCow) to avoid allocating for struct field names. - Use
Box<str>rather thanStringto use less memory.
§Feature Flags
Modules§
- backend
- stack 🔒
- string 🔒
- string_
cow 🔒 - string_
ref 🔒
Structs§
- KString
Base - A UTF-8 encoded, immutable string.
- KString
CowBase - A reference to a UTF-8 encoded, immutable string.
- KString
Ref - A reference to a UTF-8 encoded, immutable string.
- Stack
String - Fixed-size stack-allocated string
Type Aliases§
- KString
- A UTF-8 encoded, immutable string.
- KString
Cow - A reference to a UTF-8 encoded, immutable string.