[][src]Crate cervine

cervine::Cow is an alloc::borrow::Cow alternative that has different generic type constraints.

Features

"serde": Implements serde::Deserialize and serde::Serialize on Cow.

Examples

Same type (T = R = [bool; 2]):

use cervine::Cow;
use rand::prelude::*;

let data = [true, false];
let mut cow = Cow::Borrowed(&data);

if thread_rng().gen() {
  cow = Cow::Owned([false, true]);
}

let array_ref: &[bool; 2] = cow.as_ref();

Different types (T = String and R = str):

use cervine::Cow;
use rand::prelude::*;
use smartstring::alias::String;

let mut cow = Cow::Borrowed("borrowed");

if thread_rng().gen() {
  cow = Cow::Owned(String::from("owned"));
}

let str_ref: &str = cow.as_ref();

Enums

Cow

Cow is a clone-on-write smart pointer largely analogous to alloc::borrow::Cow, with one key difference:
Instead of requiring ToOwned, the owned and borrowed type are both configurable and most methods require T: Borrow<R>.