arrayref 0.3.2

Macros to take array references of slices

This package contains just four macros, which enable the creation of array references to portions of arrays or slices (or things that can be sliced).


Here is a simple example of slicing and dicing a slice into array references with these macros. Here we implement a simple little-endian conversion from bytes to u16, and demonstrate code that uses array_ref! to extract an array reference from a larger array. Note that the documentation for each macro also has an example of its use.

extern crate arrayref;

fn read_u16(bytes: &[u8; 2]) -> u16 {
     bytes[0] as u16 + ((bytes[1] as u16) << 8)
// ...
# fn main() {
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]));
# }