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