Skip to main content

object_rainbow/impls/
arc.rs

1use crate::*;
2
3impl<T: ?Sized + ToOutput> ToOutput for Arc<T> {
4    fn to_output(&self, output: &mut (impl ?Sized + Output)) {
5        (**self).to_output(output);
6    }
7}
8
9impl<T: ?Sized + InlineOutput> InlineOutput for Arc<T> {}
10
11impl<T: Parse<I>, I: ParseInput> Parse<I> for Arc<T> {
12    fn parse(input: I) -> crate::Result<Self> {
13        T::parse(input).map(Self::new)
14    }
15}
16
17impl<T: ParseInline<I>, I: ParseInput> ParseInline<I> for Arc<T> {
18    fn parse_inline(input: &mut I) -> crate::Result<Self> {
19        T::parse_inline(input).map(Self::new)
20    }
21}
22
23impl<T: ?Sized + ListHashes> ListHashes for Arc<T> {
24    fn list_hashes(&self, f: &mut (impl ?Sized + FnMut(Hash))) {
25        (**self).list_hashes(f);
26    }
27
28    fn topology_hash(&self) -> Hash {
29        (**self).topology_hash()
30    }
31
32    fn point_count(&self) -> usize {
33        (**self).point_count()
34    }
35}
36
37impl<T: ?Sized + Topological> Topological for Arc<T> {
38    fn traverse(&self, visitor: &mut (impl ?Sized + PointVisitor)) {
39        (**self).traverse(visitor);
40    }
41
42    fn topology(&self) -> TopoVec {
43        (**self).topology()
44    }
45}
46
47impl<T: ?Sized + Tagged> Tagged for Arc<T> {
48    const TAGS: Tags = T::TAGS;
49    const HASH: Hash = T::HASH;
50}
51
52impl<T: ?Sized + Size> Size for Arc<T> {
53    const SIZE: usize = T::SIZE;
54    type Size = T::Size;
55}
56
57impl<T: ?Sized + MaybeHasNiche> MaybeHasNiche for Arc<T> {
58    type MnArray = T::MnArray;
59}
60
61impl<T: Clone> Equivalent<T> for Arc<T> {
62    fn into_equivalent(self) -> T {
63        Arc::unwrap_or_clone(self)
64    }
65
66    fn from_equivalent(object: T) -> Self {
67        Arc::new(object)
68    }
69}
70
71impl<T: ?Sized + ByteOrd> ByteOrd for Arc<T> {
72    fn bytes_cmp(&self, other: &Self) -> std::cmp::Ordering {
73        (**self).bytes_cmp(other)
74    }
75}
76
77impl<T: ?Sized + FetchBytes> FetchBytes for Arc<T> {
78    fn fetch_bytes(&'_ self) -> FailFuture<'_, ByteNode> {
79        (**self).fetch_bytes()
80    }
81
82    fn fetch_data(&'_ self) -> FailFuture<'_, Vec<u8>> {
83        (**self).fetch_data()
84    }
85
86    fn fetch_bytes_local(&self) -> Result<Option<ByteNode>> {
87        (**self).fetch_bytes_local()
88    }
89
90    fn fetch_data_local(&self) -> Option<Vec<u8>> {
91        (**self).fetch_data_local()
92    }
93
94    fn as_inner(&self) -> Option<&dyn Any> {
95        (**self).as_inner()
96    }
97
98    fn as_resolve(&self) -> Option<&Arc<dyn Resolve>> {
99        (**self).as_resolve()
100    }
101
102    fn try_unwrap_resolve(self: Arc<Self>) -> Option<Arc<dyn Resolve>> {
103        Arc::try_unwrap(self).ok()?.try_unwrap_resolve()
104    }
105}
106
107impl<T: ?Sized + Singular> Singular for Arc<T> {
108    fn hash(&self) -> Hash {
109        (**self).hash()
110    }
111}
112
113impl<T: Fetch + Clone> Fetch for Arc<T> {
114    type T = T::T;
115
116    fn fetch(&'_ self) -> FailFuture<'_, Self::T> {
117        (**self).fetch()
118    }
119
120    fn try_fetch_local(&self) -> Result<Option<Self::T>> {
121        (**self).try_fetch_local()
122    }
123
124    fn fetch_local(&self) -> Option<Self::T> {
125        (**self).fetch_local()
126    }
127
128    fn get(&self) -> Option<&Self::T> {
129        (**self).get()
130    }
131
132    fn get_mut(&mut self) -> Option<&mut Self::T> {
133        Arc::make_mut(self).get_mut()
134    }
135
136    fn get_mut_finalize(&mut self) {
137        Arc::make_mut(self).get_mut_finalize();
138    }
139
140    fn try_unwrap(self: Arc<Self>) -> Option<Self::T> {
141        Arc::try_unwrap(self).ok()?.try_unwrap()
142    }
143
144    fn into_dyn_fetch<'a>(self) -> Arc<dyn 'a + Fetch<T = Self::T>>
145    where
146        Self: 'a + Sized,
147    {
148        self
149    }
150}
151
152impl<T> Fetch for Arc<dyn SingularFetch<T = T>> {
153    type T = T;
154
155    fn fetch(&'_ self) -> FailFuture<'_, Self::T> {
156        (**self).fetch()
157    }
158
159    fn try_fetch_local(&self) -> Result<Option<Self::T>> {
160        (**self).try_fetch_local()
161    }
162
163    fn fetch_local(&self) -> Option<Self::T> {
164        (**self).fetch_local()
165    }
166
167    fn get(&self) -> Option<&Self::T> {
168        (**self).get()
169    }
170
171    fn into_dyn_fetch<'a>(self) -> Arc<dyn 'a + Fetch<T = Self::T>>
172    where
173        Self: 'a + Sized,
174    {
175        self
176    }
177}