macro_rules! cow {
    ($e:expr) => { ... };
    (borrow $e:ident) => { ... };
    (own $e:expr) => { ... };
}
Expand description

Create new Cow type.

It has 3 ways to use: auto, borrowed and owned.

Examples

use std::borrow::Cow;
use sugars::cow;

let s = String::from("Hello");

let auto = cow!(&s);
let borrowed = cow!(borrow s);
let owned: Cow<'_, String> = cow!(own String::from("Owned"));
use std::borrow::Cow;
use sugars::cow;

let s = String::from("Help");
let expected: Cow<_> = Cow::Borrowed(&s);
let test: Cow<_> = cow!(&s);

assert_eq!(expected, test);