object_rainbow/
extra_none_terminated.rs1use crate::{extra_option::ExtraNoneOutput, extras::Extras, none_terminated::Nt, *};
2
3#[derive(Debug, ListHashes, Topological, Parse, ParseInline, Tagged)]
4pub struct Ent<T, E = ()> {
5 pub extra: Extras<E>,
6 pub items: Nt<T>,
7}
8
9impl<T, E: PartialEq> PartialEq for Ent<T, E>
10where
11 for<'a> &'a T: IntoIterator<Item: PartialEq>,
12{
13 fn eq(&self, other: &Self) -> bool {
14 self.extra == other.extra && self.items == other.items
15 }
16}
17
18impl<T: IntoIterator, E> IntoIterator for Ent<T, E> {
19 type Item = T::Item;
20
21 type IntoIter = T::IntoIter;
22
23 fn into_iter(self) -> Self::IntoIter {
24 self.items.into_iter()
25 }
26}
27
28impl<'a, T, E> IntoIterator for &'a Ent<T, E>
29where
30 &'a T: IntoIterator,
31{
32 type Item = <&'a T as IntoIterator>::Item;
33
34 type IntoIter = <&'a T as IntoIterator>::IntoIter;
35
36 fn into_iter(self) -> Self::IntoIter {
37 self.items.into_iter()
38 }
39}
40
41impl<'a, T, E> IntoIterator for &'a mut Ent<T, E>
42where
43 &'a mut T: IntoIterator,
44{
45 type Item = <&'a mut T as IntoIterator>::Item;
46
47 type IntoIter = <&'a mut T as IntoIterator>::IntoIter;
48
49 fn into_iter(self) -> Self::IntoIter {
50 self.items.into_iter()
51 }
52}
53
54pub trait EntOutput<E> {
55 fn ent_output(self, extra: &E, output: &mut impl Output);
56}
57
58impl<T: IntoIterator<Item = A>, E, A: ExtraNoneOutput<E> + InlineOutput> EntOutput<E> for T {
59 fn ent_output(self, extra: &E, output: &mut impl Output) {
60 for item in self {
61 item.extra_some_output(output);
62 }
63 A::extra_none_output(extra, output);
64 }
65}
66
67impl<T, E> ToOutput for Ent<T, E>
68where
69 for<'a> &'a T: EntOutput<E>,
70{
71 fn to_output(&self, output: &mut impl Output) {
72 self.items.ent_output(&self.extra, output);
73 }
74}
75
76impl<T, E> InlineOutput for Ent<T, E> where Self: ToOutput {}
77
78impl<T, E: Clone> CanonicalExtra for Ent<T, E> {
79 type Extra = E;
80
81 fn canonical_extra(&self) -> Self::Extra {
82 self.extra.canonical_extra()
83 }
84}