Trait sub_array::SubArray[][src]

pub trait SubArray {
    type Item;
    fn sub_array_ref<const N: usize>(&self, offset: usize) -> &[Self::Item; N];
fn sub_array_mut<const N: usize>(
        &mut self,
        offset: usize
    ) -> &mut [Self::Item; N]; }
Expand description

Array that can be slice into a smaller sub-array

Also see the crate level reference.

Associated Types

The value type of this array.

This is the T in [T; N] on regular arrays.

Required methods

Get a reference to a sub-array of length N starting at offset.

Panics

Panics if offset + N exceeds the length of this array.

Example
use sub_array::SubArray;

let arr: [u8; 5] = [9, 8, 7, 6, 5];

// Get a sub-array starting at offset 3
let sub: &[u8; 2] = arr.sub_array_ref(3);
assert_eq!(sub, &[6, 5]);

Get a mutable reference to a sub-array of length N starting at offset.

Panics

Panics if offset + N exceeds the length of this array.

Example
use sub_array::SubArray;

let mut arr: [u8; 5] = [9, 8, 7, 6, 5];

// Get a mutable sub-array starting at offset 0
let sub: &mut [u8; 2] = arr.sub_array_mut(0);
assert_eq!(sub, &mut [9, 8]);

Implementations on Foreign Types

Implementation on regular arrays

Implementors