mownstr

Crates.iomownstr
lib.rsmownstr
version0.3.1
created_at2020-04-30 17:01:27.262316+00
updated_at2025-03-18 11:56:34.909912+00
descriptionMaybe Owned String
homepage
repositoryhttps://github.com/pchampin/mownstr
max_upload_size
id235885
size47,096
Pierre-Antoine Champin (pchampin)

documentation

https://docs.rs/mownstr

README

MownStr: Maybe Owned String

Latest Version Documentation Actions Status

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

  • 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 to isize::MAX, not usize::MAX (despite sizes being typed as usize).

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.

Commit count: 52

cargo fmt