use std::net::IpAddr;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Relay {
pub address: IpAddr,
pub port: u16,
}
impl Relay {
pub fn new<Ip: Into<IpAddr>>(address: Ip, port: u16) -> Self {
Self {
address: address.into(),
port,
}
}
}
impl std::fmt::Display for Relay {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.address {
IpAddr::V4(address) => write!(f, "{}:{}", address, self.port),
IpAddr::V6(address) => write!(f, "[{}]:{}", address, self.port),
}
}
}