[][src]Crate cervine

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


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


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

use cervine::Cow;
use rand::prelude::*;
use std::borrow::Borrow as _;

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.borrow();

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();



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>.