iota_stardust_types/block/address/
ed25519.rs1use core::str::FromStr;
5
6use derive_more::{AsRef, Deref, From};
7
8use crate::block::Error;
9
10#[derive(
12 Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, From, AsRef, Deref, packable::Packable,
13)]
14#[as_ref(forward)]
15pub struct Ed25519Address([u8; Self::LENGTH]);
16
17impl Ed25519Address {
18 pub const KIND: u8 = 0;
21 pub const LENGTH: usize = 32;
23
24 #[inline(always)]
26 pub fn new(address: [u8; Self::LENGTH]) -> Self {
27 Self::from(address)
28 }
29}
30
31#[cfg(feature = "serde")]
32string_serde_impl!(Ed25519Address);
33
34impl FromStr for Ed25519Address {
35 type Err = Error;
36
37 fn from_str(s: &str) -> Result<Self, Self::Err> {
38 Ok(Self::new(prefix_hex::decode(s).map_err(Error::Hex)?))
39 }
40}
41
42impl core::fmt::Display for Ed25519Address {
43 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44 write!(f, "{}", prefix_hex::encode(self.0))
45 }
46}
47
48impl core::fmt::Debug for Ed25519Address {
49 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
50 write!(f, "Ed25519Address({self})")
51 }
52}