MownStr: Maybe Owned String
This crate provides MownStr,
a type for storing and exchanging read-only strings that may be either borrowed or owned.
Compared to Cow<str>:
MownStris 2/3 smaller,MownStris slightly slower to construct and deference to astr.
So using MownStr makes sense if you need to store a lot of them.
Otherwise, Cow<str> may be a better option.
Note also that MownStr can not represent strings longer than usize::MAX/2.
This theoretical limitation is not an issue in practice, because
- it still allows for huge string, e.g. 8EiB on a 64-bit architectures;
- it is not even clear that Rust supports strings bigger than that,
as
from_raw_partslimits the size of a slice toisize::MAX, notusize::MAX(despite sizes being typed asusize).
Benchmark
To run the benchmark, you need the feature criterion:
cargo bench --features criterion
Supported Rust version
This crate is tested with Rust 1.67 and with the latest stable release.