atm0s_sdn_node_alias/
lib.rs1use std::{fmt::Display, ops::Deref};
2
3use serde::{Deserialize, Serialize};
4
5mod behavior;
6mod handler;
7mod internal;
8mod msg;
9mod sdk;
10
11pub(crate) const NODE_ALIAS_SERVICE_ID: u8 = 7;
12
13pub use behavior::NodeAliasBehavior;
14pub use sdk::{NodeAliasError, NodeAliasResult, NodeAliasSdk};
15
16#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
17pub struct NodeAliasId(u64);
18
19impl Display for NodeAliasId {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 write!(f, "Alias({})", self.0)
22 }
23}
24
25impl From<u64> for NodeAliasId {
26 fn from(value: u64) -> Self {
27 Self(value)
28 }
29}
30
31impl Deref for NodeAliasId {
32 type Target = u64;
33
34 fn deref(&self) -> &Self::Target {
35 &self.0
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 #[cfg(test)]
42 mod tests {
43 use crate::NodeAliasId;
44
45 #[test]
46 fn test_node_alias_id_display() {
47 let alias_id = NodeAliasId(123);
48 assert_eq!(format!("{}", alias_id), "Alias(123)");
49 }
50
51 #[test]
52 fn test_node_alias_id_from() {
53 let value: u64 = 456;
54 let alias_id: NodeAliasId = value.into();
55 assert_eq!(*alias_id, value);
56 }
57 }
58}