use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EndpointId(String);
impl EndpointId {
pub fn new(id: String) -> Self {
EndpointId(id)
}
pub fn from(id: &str) -> Self {
EndpointId(id.to_string())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn is_dtn_scheme(&self) -> bool {
self.0.starts_with("dtn://")
}
pub fn is_null(&self) -> bool {
self.0 == "dtn:none" || self.0.is_empty()
}
}
impl From<String> for EndpointId {
fn from(id: String) -> Self {
EndpointId(id)
}
}
impl From<&str> for EndpointId {
fn from(id: &str) -> Self {
EndpointId(id.to_string())
}
}
impl fmt::Display for EndpointId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}