Struct konst::alloc_type::COW_SLICE_NEW [−][src]
pub struct COW_SLICE_NEW<'a, T: Clone + 'a>(_);
This is supported on crate feature
alloc
only.Expand description
An empty Cow<'_, [T]>
. Usable to construct a [Cow<'_, [T]>; N]
.
As of Rust 1.51.0, [Cow::Borrowed(&[][..]); LEN]
is not valid,
because Cow<'_, [T]>
isn’t copy,
but [CONST; LEN]
does work, like in the example below.
Example
use konst::alloc_type::COW_SLICE_NEW;
use std::borrow::Cow;
const SLICES: [Cow<'_, [u64]>; 6] = [COW_SLICE_NEW::<u64>::V; 6];
let mut cows = SLICES;
[3, 5, 8, 13, 21, 34].iter().copied()
.enumerate()
.filter(|(i, _)| i % 2 != 0 )
.for_each(|(i, v)|{
cows[i].to_mut().push(v)
});
assert_eq!(cows, [&[][..], &[5], &[], &[13], &[], &[34]])