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 = VALUE_1, VALUE_2, VALUE_3, ...;          // list
    SLICE: (SIZE) = VALUE;                           // move
    SLICE = clone REFERENCE;                         // clone ref
    SLICE = copy REFERENCE;                          // copy 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

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 applied to the new array

move

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

clone

the REFERENCE &[T] values are cloned into the slice
T must implement Clone

copy

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

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