split_core_array

Macro split_core_array 

Source
macro_rules! split_core_array {
    (
		let split [
			$($name:ident $( : $ty:ty)? ),* $(,)?
		] = $data:expr $(;)?
	) => { ... };
}
Expand description

Split a core arrays in core arrays.

This function is essentially split_array, but on core arrays. In fact, it is implemented using split_array and surrounds the right-hand side with array_from_core and the output arrays with array_to_core.

Also if you need to specify the size of an array you have to specifiy the full core array.

§Syntax

split_core_array!{
    let split \[
        ( <name> [ : <array-type> ] , )*
    \] = <value>;
}

§Example

use array_fusion::split_core_array;

let data = [
    0, 42, // foo
    0x0, 0x0, 0x12, 0x34, // bar
];

// Split the array, core to core
// The size of `foo` is inferred from the subsequent usage of it, whereas
// the size of `bar` is explicitly specified.
split_core_array! {
    let split [
        foo,
        bar: [_; 4],
    ] = data;
};

// Use foo in a way to make it's size inferrable
let foo = u16::from_be_bytes(foo);
assert_eq!(foo, 42);

// Use bar, actually this would also infere its size, but we specified it
// already above.
assert_eq!(u32::from_be_bytes(bar), 0x1234);