ockam_core/routing/
transport_type.rs

1use core::fmt::{self, Debug, Display};
2use minicbor::{CborLen, Decode, Encode};
3use serde::{Deserialize, Serialize};
4
5/// The transport type of an [`Address`](crate::Address).
6#[derive(
7    Serialize,
8    Deserialize,
9    Decode,
10    Encode,
11    CborLen,
12    Debug,
13    Copy,
14    Clone,
15    PartialEq,
16    Eq,
17    PartialOrd,
18    Ord,
19    Hash,
20)]
21#[serde(transparent)]
22#[cbor(transparent)]
23pub struct TransportType(#[n(0)] u8);
24
25/// The local transport type.
26pub const LOCAL: TransportType = TransportType::new(0);
27
28impl TransportType {
29    /// Create a new transport type.
30    pub const fn new(n: u8) -> Self {
31        TransportType(n)
32    }
33
34    /// Raw value
35    pub fn value(&self) -> u8 {
36        self.0
37    }
38
39    /// Is this the local transport type?
40    pub fn is_local(self) -> bool {
41        self == LOCAL
42    }
43}
44
45impl Display for TransportType {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        write!(f, "{}", self.0)
48    }
49}
50
51impl From<TransportType> for u8 {
52    fn from(ty: TransportType) -> Self {
53        ty.0
54    }
55}