lean_string

Crates.iolean_string
lib.rslean_string
version
sourcesrc
created_at2024-12-08 12:45:34.789232
updated_at2024-12-08 12:45:34.789232
descriptionCompact, clone-on-write string.
homepage
repositoryhttps://github.com/ryota2357/lean_string
max_upload_size
id1476262
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
ryota2357 (ryota2357)

documentation

README

LeanString

⚠️This is a work in progress.

Compact, clone-on-write string.

Properties

LeanString has the following properties:

  • size_of::<LeanString>() == size_of::<[usize; 2]>() (2 words).
    • one usize smaller than String.
  • Stores up to 16 bytes inline (on the stack).
    • 8 bytes if 32-bit architecture.
    • Strings larger than 16 bytes are stored on the heap.
  • Clone-on-Write (CoW)
    • LeanString uses a reference-counted heap buffer (like Arc).
    • When a LeanString is cloned, the heap buffer is shared.
    • When a LeanString is mutated, the heap buffer is copied if it is shared.
  • O(1), zero allocation construction from &'static str.
  • Nich optimized for Option<LeanString>.
    • size_of::<Option<LeanString>>() == size_of::<LeanString>()
  • High API compatibility for String.

TODOs

  • Support 32-bit architecture.
  • API compatibility with String.
  • Fuzz testing.
  • Benchmarking.
  • Documentation.
  • etc...

Example

// TODO

Which should I use?

TODO: Compare LeanString with String, EcoString, CompactString, etc...

Special Thanks

The idea and implementation of LeanString is inspired by the following projects:

I would like to thank the authors of these projects for their great work.

License

This crate is licensed under the MIT license.

Commit count: 38

cargo fmt