Constant konst::alloc_type::COW_STR_NEW
source · pub const COW_STR_NEW: Cow<'_, str>;
Available on crate feature
alloc
only.Expand description
An empty Cow<'_, str>
. Usable to construct a [Cow<'_, str>; N]
.
As of Rust 1.65.0, [Cow::Borrowed(""); LEN]
is not valid,
because Cow<'_, str>
isn’t copy,
but [COW_STR_NEW; LEN]
does work, like in the example below.
§Example
use konst::alloc_type::COW_STR_NEW;
use std::borrow::Cow;
const SIX_COWS: [Cow<'_, str>; 6] = [COW_STR_NEW; 6];
let mut cows = SIX_COWS;
('a'..='f')
.enumerate()
.filter(|(i, _)| i % 2 == 0 )
.for_each(|(i, c)|{
cows[i].to_mut().push(c)
});
assert_eq!(cows, ["a", "", "c", "", "e", ""])