1
0
Fork 0
forked from wry/wry

output: pre-compute OutputId hash

This commit is contained in:
Julian Orth 2026-04-05 14:15:38 +02:00 committed by kossLAN
parent 9bd7e14b08
commit 6e9adc487e
No known key found for this signature in database
8 changed files with 88 additions and 40 deletions

View file

@ -933,3 +933,35 @@ macro_rules! opaque {
}
};
}
macro_rules! hash_type {
($name:ident) => {
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct $name(pub [u8; 32]);
impl $name {
#[allow(clippy::allow_attributes, dead_code)]
pub fn hash(t: impl AsRef<[u8]>) -> Self {
Self(*blake3::hash(t.as_ref()).as_bytes())
}
}
impl serde::Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.serialize(serializer)
}
}
impl<'de> serde::Deserialize<'de> for $name {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
<[u8; 32]>::deserialize(deserializer).map(Self)
}
}
};
}