datalog_structural_model/digest/
output.rs1use std::{fmt, str::FromStr};
4
5use super::hex::{DigestBytes, DigestParseError};
6
7macro_rules! digest_newtype {
8 ($(#[$meta:meta])* $name:ident) => {
9 $(#[$meta])*
10 #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
11 pub struct $name(DigestBytes);
12
13 impl $name {
14 #[must_use]
16 pub const fn as_bytes(&self) -> &[u8; 32] {
17 &self.0.0
18 }
19 }
20
21 impl From<[u8; 32]> for $name {
22 fn from(bytes: [u8; 32]) -> Self {
23 Self(DigestBytes(bytes))
24 }
25 }
26
27 impl fmt::Display for $name {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 self.0.fmt(f)
30 }
31 }
32
33 impl FromStr for $name {
34 type Err = DigestParseError;
35
36 fn from_str(text: &str) -> Result<Self, Self::Err> {
37 DigestBytes::parse(text).map(Self)
38 }
39 }
40 };
41}
42
43digest_newtype!(
44 ProgramDigest
49);
50
51digest_newtype!(
52 ContractDigest
55);