Expand description
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
set_slice! {
SLICE = VALUE_1, VALUE_2, VALUE_3, ...; // list
SLICE = move VALUE; // move
SLICE = clone REFERENCE; // clone ref
SLICE = copy REFERENCE; // copy ref
unsafe SLICE: (SIZE) = ref REFERENCE; // unsafe 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
§copy
the REFERENCE
&[T]
values are copied into the slice
T
must implement Copy
§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
§unsafe copy
VERY UNSAFE
the REFERENCE
&[T]
values are copied into the slice
internally this uses ::core::mem::transmute_copy
so, use this with caution, as it may cause undefined behaviour
VERY UNSAFE
§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