Skip to main content

object_rainbow/impls/
cow.rs

1use std::borrow::Cow;
2
3use crate::*;
4
5impl<'a, B: 'a + ToOwned + ToOutput + ?Sized> ToOutput for Cow<'a, B> {
6    fn to_output(&self, output: &mut dyn crate::Output) {
7        (**self).to_output(output);
8    }
9}
10
11impl<'a, B: 'a + ToOwned + InlineOutput + ?Sized> InlineOutput for Cow<'a, B> {}
12
13impl<'a, B: 'a + ToOwned<Owned: Parse<I>> + ?Sized, I: ParseInput> Parse<I> for Cow<'a, B> {
14    fn parse(input: I) -> crate::Result<Self> {
15        input.parse().map(Self::Owned)
16    }
17}
18
19impl<'a, B: 'a + ToOwned<Owned: ParseInline<I>> + ?Sized, I: ParseInput> ParseInline<I>
20    for Cow<'a, B>
21{
22    fn parse_inline(input: &mut I) -> crate::Result<Self> {
23        input.parse_inline().map(Self::Owned)
24    }
25}
26
27impl<'a, B: 'a + ToOwned + ListHashes + ?Sized> ListHashes for Cow<'a, B> {
28    fn list_hashes(&self, f: &mut impl FnMut(Hash)) {
29        (**self).list_hashes(f);
30    }
31
32    fn topology_hash(&self) -> Hash {
33        (**self).topology_hash()
34    }
35
36    fn point_count(&self) -> usize {
37        (**self).point_count()
38    }
39}
40
41impl<'a, B: 'a + ToOwned + Topological + ?Sized> Topological for Cow<'a, B> {
42    fn traverse(&self, visitor: &mut impl PointVisitor) {
43        (**self).traverse(visitor);
44    }
45
46    fn topology(&self) -> TopoVec {
47        (**self).topology()
48    }
49}
50
51impl<'a, B: 'a + ToOwned + Tagged + ?Sized> Tagged for Cow<'a, B> {
52    const TAGS: crate::Tags = B::TAGS;
53    const HASH: crate::Hash = B::HASH;
54}
55
56impl<'a, B: 'a + ToOwned + Size + ?Sized> Size for Cow<'a, B> {
57    const SIZE: usize = B::SIZE;
58    type Size = B::Size;
59}
60
61impl<'a, B: 'a + ToOwned + MaybeHasNiche + ?Sized> MaybeHasNiche for Cow<'a, B> {
62    type MnArray = B::MnArray;
63}
64
65impl<'a, B: 'a + ToOwned + ?Sized> Equivalent<B::Owned> for Cow<'a, B> {
66    fn into_equivalent(self) -> B::Owned {
67        self.into_owned()
68    }
69
70    fn from_equivalent(object: B::Owned) -> Self {
71        Cow::Owned(object)
72    }
73}