Crates.io | dairy |
lib.rs | dairy |
version | 0.2.2 |
source | src |
created_at | 2021-06-27 17:37:46.067692 |
updated_at | 2021-07-11 10:33:27.384558 |
description | A more compact, user friendly clone-on-write smart pointer. |
homepage | |
repository | https://github.com/rossmacarthur/dairy |
max_upload_size | |
id | 415471 |
size | 103,689 |
A more compact, user friendly clone-on-write smart pointer.
use dairy::Cow;
let borrowed: Cow<str> = Cow::borrowed("Hello World!");
let owned: Cow<str> = Cow::owned(String::from("Hello World!"));
Add the following to your Cargo manifest.
[dependencies]
dairy = "0.2"
no_std
is also supported by disabling the default std
feature. An allocator
is required.
[dependencies]
dairy = { version = "0.2", default-features = false }
Serde is supported behind the serde
feature.
[dependencies]
dairy = { version = "0.2", features = ["serde"] }
dairy::Cow
is an improved version of the standard library std::borrow::Cow
.
Depending on the platform and type this crate provides a better underlying
implementation which will be more compact. This crate currently supports the
following types: str
, [T]
, CStr
, OsStr
, and Path
.
dairy::Cow
is also able to provide many more From
implementations; some
which are not possible for the standard library to provide due to the alloc
,
std
split. For example Cow<Path>
now has the useful From<&str>
implementation.
Cow
is two words wide,
storing the length, capacity, and the ownership tag in the same word.Cow
is three words wide,
storing the capacity and the ownership tag in the same word..into_raw_parts()
or
equivalent method for the owned version of types.The following table documents how Cow<T>
is implemented for each type on
depending on the platform.
Cow<T> |
Unix/WASI | Other |
---|---|---|
Cow<str> |
compact | compact |
Cow<[T]> |
compact | compact |
Cow<CStr> |
compact | compact |
Cow<OsStr> |
compact | default |
Cow<Path> |
compact | default |
Some implementation details taken from the excellent beef crate.
Licensed under either of
at your option.