Crate set_slice[][src]

A macro for setting values to slices in batch

Using this macro it is possible to set values to slices without setting each value individually

Syntax

This example is not tested
set_slice! {
    SLICE: (SIZE) = VALUE;                           // move
    SLICE = VALUE_1, VALUE_2, VALUE_3, ...;          // list
    SLICE = copy REFERENCE;                          // copy ref
    SLICE = clone REFERENCE;                         // clone ref
    ...
}

Variable Definitions

SLICE: &mut [T] = name of slice
VALUE: impl Deref<Target = [T]> | AsRef<[T]> = value to be stored in slice
SIZE: usize = a constexpr that specifies the size of the slice
REFERENCE: &[T] = a reference to a slice
copy/clone = an identifier that speficies how to handle REFERENCE

Examples

let mut slice = [0; 3]; // example slice
let vec = [-1, -2];


set_slice! {
    slice = 1, 2, 3;
    slice[..2] = copy &vec;
}

assert_eq!(slice, [-1, -2, 3]);

Semantics and Notes on Syntax

move

the VALUE is moved into set_slice and dropped
the contents of VALUE are stored into the slice

list

the list: VALUE_1, VALUE_2, VALUE_3, ... is counted and converted into an array
after conversion it is has the same semantics as move

copy

the reference slice &[T] values are copied into the slice
T must implement Copy

clone

the reference slice &[T] values are cloned into the slice
T must implement Clone Cargo features This crate provides two cargo features:

Cargo features

This crate allows for use in no-std environment.

Macros

set_slice

a macro for setting parts of slices, see crate level docs for more info