1use core::str::FromStr;
6use parse_display::Display;
7
8#[cfg_attr(feature = "json_schema", derive(schemars::JsonSchema))]
28#[cfg_attr(
29 feature = "serde",
30 derive(serde_with::SerializeDisplay, serde_with::DeserializeFromStr)
31)]
32#[repr(transparent)]
33#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Display)]
34#[display("{0:#x}")]
35pub struct Signature(u32);
36
37impl Signature {
38 #[inline]
40 pub const fn new(sig: u32) -> Self {
41 Self(sig)
42 }
43
44 #[inline]
46 pub const fn get(self) -> u32 {
47 self.0
48 }
49}
50
51impl FromStr for Signature {
52 type Err = &'static str;
53
54 #[inline]
55 fn from_str(s: &str) -> Result<Self, Self::Err> {
56 Ok(Self::new(
57 crate::parse_int::ParseNumber::parse(s)
58 .map_err(|_err| "Invalid integer for Signature")?,
59 ))
60 }
61}
62
63impl From<u32> for Signature {
64 #[inline]
65 fn from(value: u32) -> Self {
66 Self(value)
67 }
68}
69
70impl From<Signature> for u32 {
71 #[inline]
72 fn from(value: Signature) -> Self {
73 value.0
74 }
75}