Crate arrayref[−][src]
Expand description
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).
Examples
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.
#[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]));
Macros
array_mut_ref | You can use |
array_ref | You can use |
array_refs | You can use |
mut_array_refs | You can use |