iota_stardust_types/block/address/
alias.rs1use core::str::FromStr;
5
6use derive_more::{AsRef, Deref, From};
7
8use crate::block::{
9 Error,
10 output::{AliasId, OutputId},
11};
12
13#[derive(
15 Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, From, AsRef, Deref, packable::Packable,
16)]
17#[as_ref(forward)]
18pub struct AliasAddress(AliasId);
19
20impl AliasAddress {
21 pub const KIND: u8 = 8;
24 pub const LENGTH: usize = AliasId::LENGTH;
26
27 #[inline(always)]
29 pub fn new(id: AliasId) -> Self {
30 Self::from(id)
31 }
32
33 #[inline(always)]
35 pub fn alias_id(&self) -> &AliasId {
36 &self.0
37 }
38
39 #[inline(always)]
41 pub fn into_alias_id(self) -> AliasId {
42 self.0
43 }
44}
45
46#[cfg(feature = "serde")]
47string_serde_impl!(AliasAddress);
48
49impl FromStr for AliasAddress {
50 type Err = Error;
51
52 fn from_str(s: &str) -> Result<Self, Self::Err> {
53 Ok(Self::new(AliasId::from_str(s)?))
54 }
55}
56
57impl From<&OutputId> for AliasAddress {
58 fn from(output_id: &OutputId) -> Self {
59 Self(AliasId::from(output_id))
60 }
61}
62
63impl core::fmt::Display for AliasAddress {
64 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 write!(f, "{}", self.0)
66 }
67}
68
69impl core::fmt::Debug for AliasAddress {
70 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 write!(f, "AliasAddress({self})")
72 }
73}