object_rainbow/
default_terminated.rs1use std::sync::Arc;
2
3use crate::*;
4
5#[derive(ParseAsInline)]
6pub struct Dt<T, A> {
7 inner: Arc<(T, A)>,
8}
9
10impl<T, A> Clone for Dt<T, A> {
11 fn clone(&self) -> Self {
12 Self {
13 inner: self.inner.clone(),
14 }
15 }
16}
17
18impl<T, A> Deref for Dt<T, A> {
19 type Target = T;
20
21 fn deref(&self) -> &Self::Target {
22 &self.inner.0
23 }
24}
25
26impl<T, A: Default + InlineOutput> ToOutput for Dt<T, A>
27where
28 for<'a> &'a T: IntoIterator<Item: InlineOutput>,
29{
30 fn to_output(&self, output: &mut impl Output) {
31 self.iter_to_output(output);
32 self.inner.1.to_output(output);
33 }
34}
35
36impl<T, A: Default + InlineOutput> InlineOutput for Dt<T, A> where
37 for<'a> &'a T: IntoIterator<Item: InlineOutput>
38{
39}
40
41impl<T, A> ListHashes for Dt<T, A>
42where
43 for<'a> &'a T: IntoIterator<Item: ListHashes>,
44{
45 fn list_hashes(&self, f: &mut impl FnMut(Hash)) {
46 self.iter_list_hashes(f);
47 }
48}
49
50impl<T, A> Topological for Dt<T, A>
51where
52 for<'a> &'a T: IntoIterator<Item: Topological>,
53{
54 fn traverse(&self, visitor: &mut impl PointVisitor) {
55 self.iter_traverse(visitor);
56 }
57}
58
59impl<T: Tagged, A> Tagged for Dt<T, A> {
60 const TAGS: Tags = T::TAGS;
61}
62
63impl<T: FromIterator<A>, A: PartialEq + Default + ParseInline<I>, I: ParseInput> ParseInline<I>
64 for Dt<T, A>
65{
66 fn parse_inline(input: &mut I) -> crate::Result<Self> {
67 let mut items = Vec::new();
68 let default = A::default();
69 let term = loop {
70 let item = input.parse_inline()?;
71 if item == default {
72 break item;
73 }
74 items.push(item);
75 };
76 let inner = Arc::new((items.into_iter().collect(), term));
77 Ok(Self { inner })
78 }
79}