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

Download history 1019/week @ 2024-12-04 686/week @ 2024-12-11 496/week @ 2024-12-18 39/week @ 2024-12-25 256/week @ 2025-01-01 627/week @ 2025-01-08 419/week @ 2025-01-15 354/week @ 2025-01-22 323/week @ 2025-01-29 599/week @ 2025-02-05 416/week @ 2025-02-12 367/week @ 2025-02-19 372/week @ 2025-02-26 311/week @ 2025-03-05 603/week @ 2025-03-12 602/week @ 2025-03-19

1,945 downloads per month
Used in 46 crates (2 directly)

CECILL-B

18KB
407 lines

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.

Dependencies

~0–9.5MB
~87K SLoC