LString
Key String: Optimized for map keys.
This crate is extended and more feature rich version of kstring with some significant changes.
Internal representation of string types still is same so you can convert corresponding types between both crates (see kstring feature).
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.
Significant changes:
- Because
From<&'static str>is unsound it changed toFrom<&str>. To instantiate from static str useKString::from_staticinstead ofFrom::from(or [kstring] macro). - Added default generic to types
KStringBaseandKStringCowBasewhich renamed toKStringandKStringCow. Corresponding type aliases is removed. To instantiate types with default backend wrap it with angle brackets (KString::from_ref("abc")=><KString>::from_ref("abc")). - Added
KStringWriterandkformatmacros. Also addedFromIteratortrait impls - Added
from_utf8andfrom_utf16functions.
Features:
max_inline: Instead of aligning the inline-string for performance (15 bytes + length on 64-bit), use the full width (22 bytes on 64-bit)arc: Instead of usingBox<str>, useArc<str>. Note: allocations are fast enough that this can actually slow things down for small enough strings.serde: Enables serde support (AddsSerialize/Deserializetraits impls).quote: Enables quote support (AddsToTokenstrait impls).diesel: Enables diesel support (AddsToSql/FromSqltraits impls).kstring: Enables conversion from/into corresponding kstring types.
Alternatives, see rust-string-comparison and string-benchmarks-rs.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.