Struct konst::alloc_type::COW_SLICE_NEW
source · pub struct COW_SLICE_NEW<'a, T: Clone + 'a>(/* private fields */);
Available on crate feature
alloc
only.Expand description
An empty Cow<'_, [T]>
. Usable to construct a [Cow<'_, [T]>; N]
.
As of Rust 1.65.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]])
Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for COW_SLICE_NEW<'a, T>
impl<'a, T> RefUnwindSafe for COW_SLICE_NEW<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for COW_SLICE_NEW<'a, T>where
T: Send,
impl<'a, T> Sync for COW_SLICE_NEW<'a, T>where
T: Sync,
impl<'a, T> Unpin for COW_SLICE_NEW<'a, T>where
T: Unpin,
impl<'a, T> UnwindSafe for COW_SLICE_NEW<'a, T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more