devela/data/list/array/d2/
impl_traits.rs
1#[cfg(feature = "alloc")]
7use crate::Boxed;
8use crate::{Array, Array2d, Bare, ConstDefault, Storage};
9use core::fmt;
10
11#[rustfmt::skip]
14impl<T: Clone, const C: usize, const R: usize, const CR: usize, const RMAJ: bool, S: Storage>
15Clone for Array2d<T, C, R, CR, RMAJ, S> where S::Stored<[T; CR]>: Clone {
16 fn clone(&self) -> Self {
17 Self { data: self.data.clone() }
18 }
19}
20#[rustfmt::skip]
21impl<T: Copy, const C: usize, const R: usize, const CR: usize, const RMAJ: bool, S: Storage>
22Copy for Array2d<T, C, R, CR, RMAJ, S> where S::Stored<[T; CR]>: Copy {}
23
24#[rustfmt::skip]
26impl<T: fmt::Debug, const C: usize, const R: usize, const CR: usize, S: Storage, const RMAJ: bool>
27fmt::Debug for Array2d<T, C, R, CR, RMAJ, S> where S::Stored<[T; CR]>: fmt::Debug {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 f.debug_struct("Array2d")
30 .field("T", &core::any::type_name::<T>())
31 .field("S", &S::name())
32 .field("C", &C).field("R", &R).field("CR", &CR).field("RMAJ", &RMAJ)
33 .field("data", &self.data)
34 .finish()
35 }
36}
37
38#[rustfmt::skip]
41impl<T: PartialEq, const C: usize, const R: usize, const CR: usize, const RMAJ: bool, S: Storage>
42PartialEq for Array2d<T, C, R, CR, RMAJ, S> where S::Stored<[T; CR]>: PartialEq {
43 fn eq(&self, other: &Self) -> bool {
44 self.data == other.data && self.capacity() == other.capacity()
45 }
46}
47#[rustfmt::skip]
48impl<T: Eq, const C: usize, const R: usize, const CR: usize, const RMAJ: bool, S: Storage>
49Eq for Array2d<T, C, R, CR, RMAJ, S> where S::Stored<[T; CR]>: Eq {}
50
51impl<T: Default, const C: usize, const R: usize, const CR: usize, const RMAJ: bool> Default
55 for Array2d<T, C, R, CR, RMAJ, Bare>
56{
57 fn default() -> Self {
62 Self::panic_check_CR();
63 Self { data: Array::<T, CR, Bare>::default() }
64 }
65}
66
67impl<T: ConstDefault, const C: usize, const R: usize, const CR: usize, const RMAJ: bool>
69 ConstDefault for Array2d<T, C, R, CR, RMAJ, Bare>
70{
71 const DEFAULT: Self = {
76 Self::panic_check_CR();
77 Self { data: Array::<T, CR, Bare>::DEFAULT }
78 };
79}
80
81#[cfg(feature = "alloc")]
83#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "alloc")))]
84impl<T: Default, const C: usize, const R: usize, const CR: usize, const RMAJ: bool> Default
85 for Array2d<T, C, R, CR, RMAJ, Boxed>
86{
87 fn default() -> Self {
96 Self::panic_check_CR();
97 Self { data: Array::<T, CR, Boxed>::default() }
98 }
99}