| Crates.io | mownstr |
| lib.rs | mownstr |
| version | 0.3.1 |
| created_at | 2020-04-30 17:01:27.262316+00 |
| updated_at | 2025-03-18 11:56:34.909912+00 |
| description | Maybe Owned String |
| homepage | |
| repository | https://github.com/pchampin/mownstr |
| max_upload_size | |
| id | 235885 |
| size | 47,096 |
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 a str.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
from_raw_parts limits the size of a slice to isize::MAX,
not usize::MAX (despite sizes being typed as usize).To run the benchmark, you need the feature criterion:
cargo bench --features criterion
This crate is tested with Rust 1.67 and with the latest stable release.