pub trait SubArray {
type Item;
// Required methods
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.
Required Associated Types§
Required Methods§
Sourcefn sub_array_ref<const N: usize>(&self, offset: usize) -> &[Self::Item; N]
fn sub_array_ref<const N: usize>(&self, offset: usize) -> &[Self::Item; N]
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]);
Sourcefn sub_array_mut<const N: usize>(
&mut self,
offset: usize,
) -> &mut [Self::Item; N]
fn sub_array_mut<const N: usize>( &mut self, offset: usize, ) -> &mut [Self::Item; N]
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]);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.