devela/num/geom/linear/vector/array/
impl_traits.rs
1use crate::{array_init, ConstDefault, Hash, Hasher, Vector, _core::fmt};
7
8impl<T: Clone, const D: usize> Clone for Vector<T, D> {
12 fn clone(&self) -> Self {
13 Self { coords: self.coords.clone() }
14 }
15}
16
17impl<T: Copy, const D: usize> Copy for Vector<T, D> {}
19
20impl<T: Default, const D: usize> Default for Vector<T, D> {
23 fn default() -> Self {
26 let coords = array_init![default [T; D], "safe_num", "unsafe_array"];
27 Self { coords }
28 }
29}
30
31impl<T: ConstDefault, const D: usize> ConstDefault for Vector<T, D> {
33 const DEFAULT: Self = {
36 let coords = array_init![const_default [T; D]];
37 Self { coords }
38 };
39}
40
41impl<T: fmt::Debug, const D: usize> fmt::Debug for Vector<T, D> {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 f.debug_struct("Vector").field("D", &D).field("coords", &self.coords).finish()
45 }
46}
47
48impl<T: PartialEq, const D: usize> PartialEq for Vector<T, D> {
50 fn eq(&self, other: &Self) -> bool {
51 self.coords == other.coords
52 }
53}
54impl<T: Eq, const D: usize> Eq for Vector<T, D> {}
56
57impl<T: Hash, const D: usize> Hash for Vector<T, D> {
58 fn hash<HR: Hasher>(&self, state: &mut HR) {
59 self.coords.hash(state);
60 }
61}