8 releases
0.3.1 | Mar 18, 2025 |
---|---|
0.3.0 | Oct 2, 2024 |
0.2.1 | Feb 13, 2023 |
0.1.3 | Dec 20, 2021 |
0.1.0 | Apr 30, 2020 |
#289 in Rust patterns
1,945 downloads per month
Used in 46 crates
(2 directly)
18KB
407 lines
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>
:
MownStr
is 2/3 smaller,MownStr
is 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_parts
limits 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.
Dependencies
~0–9.5MB
~87K SLoC