Skip to main content

object_rainbow/
hashed.rs

1use std::ops::Deref;
2
3use crate::*;
4
5/// Wrapper, whose [`ToOutput`] just yields `T`'s [`ToOutput::data_hash`].
6#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Tagged, Default)]
7pub struct Hashed<T>(pub T);
8
9impl<T> Deref for Hashed<T> {
10    type Target = T;
11
12    fn deref(&self) -> &Self::Target {
13        &self.0
14    }
15}
16
17impl<T: ToOutput> ToOutput for Hashed<T> {
18    fn to_output(&self, output: &mut impl Output) {
19        if output.is_mangling() {
20            self.0.to_output(output);
21        }
22        self.0.data_hash().to_output(output);
23    }
24}
25
26impl<T: ToOutput> InlineOutput for Hashed<T> {}
27
28impl<T: ToOutput> Size for Hashed<T> {
29    const SIZE: usize = Hash::SIZE;
30    type Size = <Hash as Size>::Size;
31}