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]])

Implementations

The value that this constructs.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.