dairy

Crates.io Version Docs.rs Latest Build Status

A more compact, user friendly clone-on-write smart pointer.

rust use dairy::Cow; let borrowed: Cow<str> = Cow::borrowed("Hello World!"); let owned: Cow<str> = Cow::owned(String::from("Hello World!"));

🚀 Getting started

Add the following to your Cargo manifest.

toml [dependencies] dairy = "0.2"

no_std is also supported by disabling the default std feature. An allocator is required.

toml [dependencies] dairy = { version = "0.2", default-features = false }

Serde is supported behind the serde feature.

toml [dependencies] dairy = { version = "0.2", features = ["serde"] }

🤔 Description

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.

Underlying implementation

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 |

Acknowledgements

Some implementation details taken from the excellent beef crate.

License

Licensed under either of

at your option.