1use crate::{CardIdx, Dim, EmptyCard, IntoIdx, NVec, NVecCoreSealed, NVecMut};
2use core::fmt::Debug;
3use core::marker::PhantomData;
4
5#[derive(Clone, Copy)]
7pub struct EmptyVec<D: Dim, T> {
8 phantom: PhantomData<(D, T)>,
9}
10
11impl<D: Dim, T> Default for EmptyVec<D, T> {
12 fn default() -> Self {
13 Self {
14 phantom: Default::default(),
15 }
16 }
17}
18
19impl<D: Dim, T> Debug for EmptyVec<D, T> {
20 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21 write!(
22 f,
23 "{{ kind: EmptyVec, dim: D{}, values: [] }}",
24 D::dimension()
25 )
26 }
27}
28
29impl<D: Dim, T> NVecCoreSealed<D, T> for EmptyVec<D, T> {
30 fn core_num_children(&self) -> usize {
31 0
32 }
33
34 fn core_card(&self, idx: impl Into<<D as Dim>::CardIdx>) -> usize {
35 let idx = idx.into();
36 match CardIdx::<D>::is_d0(&idx) {
37 true => 0,
38 false => EmptyCard::<D>::panic_oob(idx),
39 }
40 }
41
42 #[allow(unreachable_code)]
43 fn core_child(&self, i: <D as Dim>::ChildIdx) -> impl NVecCoreSealed<<D as Dim>::PrevDim, T> {
44 EmptyCard::<D>::panic_oob(i);
45 EmptyVec::<_, T>::default()
46 }
47
48 fn core_map<F: FnMut(&T) -> O, O>(&self, idx: impl IntoIdx<D>, _: &mut F) -> O {
49 EmptyCard::<D>::panic_oob(idx)
50 }
51
52 fn core_is_rectangular(&self) -> bool {
53 true
54 }
55}
56
57impl<D: Dim, T> NVec<D, T> for EmptyVec<D, T> {
58 fn at(&self, idx: impl IntoIdx<D>) -> T {
59 EmptyCard::<D>::panic_oob(idx)
60 }
61
62 #[allow(unreachable_code)]
63 fn child(&self, i: <D as Dim>::ChildIdx) -> impl NVec<<D as Dim>::PrevDim, T> {
64 EmptyCard::<D>::panic_oob(i);
65 EmptyVec::default()
66 }
67
68 fn all(&self) -> impl Iterator<Item = T> {
69 core::iter::empty()
70 }
71}
72
73impl<D: Dim, T> NVecMut<D, T> for EmptyVec<D, T> {
74 fn at_mut<Idx: IntoIdx<D>>(&mut self, idx: Idx) -> &mut T {
75 EmptyCard::<D>::panic_oob(idx)
76 }
77
78 fn set<Idx: IntoIdx<D>>(&mut self, idx: Idx, _: T) {
79 EmptyCard::<D>::panic_oob(idx)
80 }
81
82 #[allow(unreachable_code)]
83 fn child_mut(&mut self, i: <D as Dim>::ChildIdx) -> impl NVecMut<<D as Dim>::PrevDim, T> {
84 EmptyCard::<D>::panic_oob(i);
85 EmptyVec::default()
86 }
87
88 fn mut_all<F>(&mut self, _: F)
89 where
90 F: FnMut(&mut T),
91 {
92 }
93
94 fn reset_all(&mut self, _: T)
95 where
96 T: PartialEq + Copy,
97 {
98 }
99}