pub unsafe trait Arraywhere
Self: Array + AsMut<[Self::Scalar]> + AsRef<[Self::Scalar]> + Borrow<[Self::Scalar]> + BorrowMut<[Self::Scalar]> + IntoIterator<Item = Self::Scalar> + Sized + StructuralPartialEq + Thin + Index<usize, Output = Self::Scalar> + Index<Range<usize>, Output = [Self::Scalar]> + Index<RangeFrom<usize>, Output = [Self::Scalar]> + Index<RangeFull, Output = [Self::Scalar]> + Index<RangeInclusive<usize>, Output = [Self::Scalar]> + Index<RangeTo<usize>, Output = [Self::Scalar]> + Index<RangeToInclusive<usize>, Output = [Self::Scalar]> + Index<(Bound<usize>, Bound<usize>), Output = [Self::Scalar]> + IndexMut<usize, Output = Self::Scalar> + IndexMut<Range<usize>, Output = [Self::Scalar]> + IndexMut<RangeFrom<usize>, Output = [Self::Scalar]> + IndexMut<RangeFull, Output = [Self::Scalar]> + IndexMut<RangeInclusive<usize>, Output = [Self::Scalar]> + IndexMut<RangeTo<usize>, Output = [Self::Scalar]> + IndexMut<RangeToInclusive<usize>, Output = [Self::Scalar]> + IndexMut<(Bound<usize>, Bound<usize>), Output = [Self::Scalar]>,{
type Scalar: Sized;
const LEN: usize;
// Required methods
fn repeat(value: Self::Scalar) -> Self
where Self::Scalar: Clone;
fn from_fn<F: FnMut(usize) -> Self::Scalar>(f: F) -> Self;
fn each_ref(&self) -> impl Array<Scalar = &Self::Scalar>;
fn each_mut(&mut self) -> impl Array<Scalar = &mut Self::Scalar>;
fn map<F: FnMut(Self::Scalar) -> U, U>(
self,
op: F,
) -> impl Array<Scalar = U>;
fn as_slice(&self) -> &[Self::Scalar];
fn as_mut_slice(&mut self) -> &mut [Self::Scalar];
}Expand description
Denotes an array.
This trait allows abstracting unsized arrays.
It provides the methods and functions provided by both [_; _] and the array module.
When both associated_type_defaults and generic_const_exprs stabilise, this trait may become deprecated.
§Safety
Self must always be [Self::Scalar; Self::LEN].
Furthermore, all items must behave exactly as their standard counterparts.
§Examples
Random-access arrays:
use multitype::Array;
fn get_4th_element<T: Array<Scalar: Copy>>(data: T) -> Option<T::Scalar> {
data.as_slice().get(4).copied()
}
assert_eq!(
get_4th_element([0, 1, 1, 2, 3, 5]),
Some(3),
);
assert_eq!(
get_4th_element([3, 1, 4, 1, 6]),
Some(6),
);
assert_eq!(
get_4th_element([1, 6, 1, 8]),
None,
);Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn as_mut_slice(&mut self) -> &mut [Self::Scalar]
fn as_mut_slice(&mut self) -> &mut [Self::Scalar]
See <[_; _]>::as_mut_slice.
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.