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.
- Auto: Uses the
Cow::from
in the passed expression - Borrowed: Uses
Cow::Borrowed
in the passed expression - Owned: Uses
Cow::Owned
in the passed expression
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);