use std::fmt;
pub type Information = String;
#[derive(Debug, Default, Clone)]
pub struct ConnectionInformation {
pub network_type: String,
pub address_type: String,
pub address: Option<Address>,
}
impl fmt::Display for ConnectionInformation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(address) = &self.address {
write!(f, "{} {} {}", self.network_type, self.address_type, address,)
} else {
write!(f, "{} {}", self.network_type, self.address_type,)
}
}
}
#[derive(Debug, Default, Clone)]
pub struct Address {
pub address: String,
pub ttl: Option<isize>,
pub range: Option<isize>,
}
impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut parts = vec![self.address.to_owned()];
if let Some(t) = &self.ttl {
parts.push(t.to_string());
}
if let Some(r) = &self.range {
parts.push(r.to_string());
}
write!(f, "{}", parts.join("/"))
}
}
#[derive(Debug, Default, Clone)]
pub struct Bandwidth {
pub experimental: bool,
pub bandwidth_type: String,
pub bandwidth: u64,
}
impl fmt::Display for Bandwidth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let output = if self.experimental { "X-" } else { "" };
write!(f, "{}{}:{}", output, self.bandwidth_type, self.bandwidth)
}
}
pub type EncryptionKey = String;
#[derive(Debug, Default, Clone)]
pub struct Attribute {
pub key: String,
pub value: Option<String>,
}
impl fmt::Display for Attribute {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(value) = &self.value {
write!(f, "{}:{}", self.key, value)
} else {
write!(f, "{}", self.key)
}
}
}
impl Attribute {
pub fn new(key: String, value: Option<String>) -> Self {
Attribute { key, value }
}
pub fn is_ice_candidate(&self) -> bool {
self.key.as_str() == "candidate"
}
}