emissary_core/primitives/
mod.rs1use core::{fmt, ops::Deref};
20
21pub use capabilities::Capabilities;
22pub use datagram_flags::DatagramFlags;
23pub use date::Date;
24pub use destination::{Destination, DestinationId};
25pub use lease_set::{Lease, LeaseSet2, LeaseSet2Header};
26pub use mapping::Mapping;
27pub use offline_signature::OfflineSignature;
28pub use router_address::{RouterAddress, TransportKind};
29pub use router_identity::{RouterId, RouterIdentity};
30pub use router_info::RouterInfo;
31pub use string::Str;
32
33#[cfg(test)]
34pub use router_info::RouterInfoBuilder;
35
36mod capabilities;
37mod datagram_flags;
38mod date;
39mod destination;
40mod lease_set;
41mod mapping;
42mod offline_signature;
43mod router_address;
44mod router_identity;
45mod router_info;
46mod string;
47
48const LOG_TARGET: &str = "emissary::primitives";
50
51#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
53pub struct TunnelId(u32);
54
55impl TunnelId {
56 #[cfg(test)]
57 pub fn random() -> TunnelId {
58 use rand::RngCore;
59
60 TunnelId::from(rand::thread_rng().next_u32())
61 }
62}
63
64impl From<u32> for TunnelId {
65 fn from(value: u32) -> Self {
66 TunnelId(value)
67 }
68}
69
70impl From<TunnelId> for u32 {
71 fn from(value: TunnelId) -> Self {
72 value.0
73 }
74}
75
76impl Deref for TunnelId {
77 type Target = u32;
78
79 fn deref(&self) -> &Self::Target {
80 &self.0
81 }
82}
83
84impl fmt::Display for TunnelId {
85 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 write!(f, "{}", self.0)
87 }
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
92pub struct MessageId(u32);
93
94impl MessageId {
95 #[cfg(test)]
96 pub fn random() -> MessageId {
97 use rand::RngCore;
98
99 MessageId::from(rand::thread_rng().next_u32())
100 }
101}
102
103impl From<u32> for MessageId {
104 fn from(value: u32) -> Self {
105 MessageId(value)
106 }
107}
108
109impl From<MessageId> for u32 {
110 fn from(value: MessageId) -> Self {
111 value.0
112 }
113}
114
115impl fmt::Display for MessageId {
116 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117 write!(f, "{}", self.0)
118 }
119}
120
121impl Deref for MessageId {
122 type Target = u32;
123
124 fn deref(&self) -> &Self::Target {
125 &self.0
126 }
127}