bee_block/output/
alias_id.rs1use crate::output::OutputId;
5
6impl_id!(pub AliasId, 32, "TODO.");
7
8#[cfg(feature = "serde")]
9string_serde_impl!(AliasId);
10
11impl From<OutputId> for AliasId {
12 fn from(output_id: OutputId) -> Self {
13 Self::from(output_id.hash())
14 }
15}
16
17impl AliasId {
18 pub fn or_from_output_id(self, output_id: OutputId) -> Self {
20 if self.is_null() { Self::from(output_id) } else { self }
21 }
22}
23
24#[cfg(feature = "dto")]
25#[allow(missing_docs)]
26pub mod dto {
27 use serde::{Deserialize, Serialize};
28
29 use super::*;
30 use crate::error::dto::DtoError;
31
32 #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
33 pub struct AliasIdDto(pub String);
34
35 impl From<&AliasId> for AliasIdDto {
36 fn from(value: &AliasId) -> Self {
37 Self(value.to_string())
38 }
39 }
40
41 impl TryFrom<&AliasIdDto> for AliasId {
42 type Error = DtoError;
43
44 fn try_from(value: &AliasIdDto) -> Result<Self, Self::Error> {
45 value
46 .0
47 .parse::<AliasId>()
48 .map_err(|_| DtoError::InvalidField("alias id"))
49 }
50 }
51}