futuresdr_types/
port_id.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4/// Port Identifier
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct PortId(String);
7
8impl PortId {
9    /// Create PortId from String
10    pub fn new(s: impl Into<String>) -> Self {
11        let mut s = s.into();
12        s = s
13            .strip_prefix("r#")
14            .map(|rest| rest.to_string())
15            .unwrap_or(s);
16        Self(s)
17    }
18
19    /// Get Name
20    pub fn name(&self) -> &str {
21        &self.0
22    }
23}
24
25impl Default for PortId {
26    fn default() -> Self {
27        Self::new("")
28    }
29}
30
31impl From<&str> for PortId {
32    fn from(item: &str) -> Self {
33        PortId::new(item)
34    }
35}
36
37impl From<String> for PortId {
38    fn from(item: String) -> Self {
39        PortId::new(item)
40    }
41}