Crates.io | cowstr |
lib.rs | cowstr |
version | 1.3.0 |
source | src |
created_at | 2022-09-28 15:16:12.289038 |
updated_at | 2024-01-23 10:22:33.731548 |
description | Copy-on-Write shared strings |
homepage | |
repository | https://git.pipapo.org/cehteh/cowstr.git |
max_upload_size | |
id | 675853 |
size | 175,766 |
This library defines strings with copy-on-write semantics.
Is a String that can be initialized to a static string or be build dynamically. Its contents can then be immutably shared and reference counted. When mutation is required the string will be copied first.
This resembles a improved Arc<Cow<'static, str>>
with some differences:
Arc
to String
to the actual data.Weak
references.CowStr
can be interior-mutable extended (append at the end).AllocationStrategy
CowStr
implements many of the std::String
methods. Missing methods will be added as required,
PR's are welcome.
Refers to an immutable slice inside of a CowStr
. This somewhat resembles the String
/&str
relationship while SubStr
keeping a strong reference to its orgin CowStr
and thus don't
need lifetimes.
serde wrapping the default string (de)serialization.
nightly enable some nightly optimizations and extensions
CowStr
is made for sharing immutable strings, a short single CowStr
will occupy slightly
more memory than a std String
. But as soon a CowStr
is cloned or SubStr
's are used
it pays back. Especially since SubStr
don't need lifetimes as they use reference counting
memory management becomes significantly easier.
Because rust has yet incomplete support for DST's CowStr
needs some unsafe code. This is
liberally chosen, when possible contracts are enforced by debug_assert
's.
CowStr
commes with an extensive test suite. 'cargo-mutants' is used to detect missing
tests. Releases must pass testing under 'miri'.