pub unsafe trait SubArray {
type Item;
// Required methods
fn sub_array_ref<const OFFSET: usize, const M: usize>(
&self,
) -> &[Self::Item; M];
fn sub_array_mut<const OFFSET: usize, const M: usize>(
&mut self,
) -> &mut [Self::Item; M];
}
Expand description
Required Associated Types§
Required Methods§
Sourcefn sub_array_ref<const OFFSET: usize, const M: usize>(&self) -> &[Self::Item; M]
fn sub_array_ref<const OFFSET: usize, const M: usize>(&self) -> &[Self::Item; M]
Get a reference to a sub-array of length M
starting at OFFSET
.
§Safety
Implementation guarantees to generate a compile-time error
when M + OFFSET
is greater than the size of the array
that sub-array is being extracted from.
§Example
use const_sub_array::SubArray;
let arr: [u8; 5] = [9, 8, 7, 6, 5];
// Get a sub-array starting at offset 3 and size 2.
let sub: &[u8; 2] = arr.sub_array_ref::<3, 2>();
assert_eq!(sub, &[6, 5]);
Sourcefn sub_array_mut<const OFFSET: usize, const M: usize>(
&mut self,
) -> &mut [Self::Item; M]
fn sub_array_mut<const OFFSET: usize, const M: usize>( &mut self, ) -> &mut [Self::Item; M]
Get a mutable reference to a sub-array of length M
starting at OFFSET
.
§Example
use const_sub_array::SubArray;
let mut arr: [u8; 5] = [9, 8, 7, 6, 5];
// Get a mutable sub-array starting at offset 0 and size 2.
let sub: &mut [u8; 2] = arr.sub_array_mut::<0, 2>();
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.