arrayref

Macro array_ref

Source
macro_rules! array_ref {
    ($arr:expr, $offset:expr, $len:expr) => { ... };
}
Expand description

You can use array_ref to generate an array reference to a subset of a sliceable bit of data (which could be an array, or a slice, or a Vec).

Panics if the slice is out of bounds.

#[macro_use]
extern crate arrayref;

fn read_u16(bytes: &[u8; 2]) -> u16 {
     bytes[0] as u16 + ((bytes[1] as u16) << 8)
}
// ...
let data = [0,1,2,3,4,0,6,7,8,9];
assert_eq!(256, read_u16(array_ref![data,0,2]));
assert_eq!(4, read_u16(array_ref![data,4,2]));