#[allow(unused_imports)]
use std::{fmt::Display, net::SocketAddr, sync::Arc};
#[derive(Debug)]
#[non_exhaustive]
#[allow(missing_docs)]
pub enum SomeSocketAddr {
Tcp(SocketAddr),
#[cfg(all(feature = "unix", unix))]
#[cfg_attr(docsrs_alt, doc(cfg(all(feature = "unix", unix))))]
Unix(tokio::net::unix::SocketAddr),
#[cfg(feature = "inetd")]
#[cfg_attr(docsrs_alt, doc(cfg(feature = "inetd")))]
Stdio,
#[cfg(feature = "multi-listener")]
#[cfg_attr(docsrs_alt, doc(cfg(feature = "multi-listener")))]
Multiple,
}
impl Display for SomeSocketAddr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SomeSocketAddr::Tcp(x) => x.fmt(f),
#[cfg(all(feature = "unix", unix))]
SomeSocketAddr::Unix(_x) => "unix".fmt(f),
#[cfg(feature = "inetd")]
SomeSocketAddr::Stdio => "stdio".fmt(f),
#[cfg(feature = "multi-listener")]
SomeSocketAddr::Multiple => "multiple".fmt(f),
}
}
}
impl SomeSocketAddr {
#[must_use]
pub fn clonable(self) -> SomeSocketAddrClonable {
match self {
SomeSocketAddr::Tcp(x) => SomeSocketAddrClonable::Tcp(x),
#[cfg(all(feature = "unix", unix))]
SomeSocketAddr::Unix(x) => SomeSocketAddrClonable::Unix(Arc::new(x)),
#[cfg(feature = "inetd")]
SomeSocketAddr::Stdio => SomeSocketAddrClonable::Stdio,
#[cfg(feature = "multi-listener")]
SomeSocketAddr::Multiple => SomeSocketAddrClonable::Multiple,
}
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
#[allow(missing_docs)]
pub enum SomeSocketAddrClonable {
Tcp(SocketAddr),
#[cfg(all(feature = "unix", unix))]
#[cfg_attr(docsrs_alt, doc(cfg(all(feature = "unix", unix))))]
Unix(Arc<tokio::net::unix::SocketAddr>),
#[cfg(feature = "inetd")]
#[cfg_attr(docsrs_alt, doc(cfg(feature = "inetd")))]
Stdio,
#[cfg(feature = "multi-listener")]
#[cfg_attr(docsrs_alt, doc(cfg(feature = "multi-listener")))]
Multiple,
}
impl Display for SomeSocketAddrClonable {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SomeSocketAddrClonable::Tcp(x) => x.fmt(f),
#[cfg(all(feature = "unix", unix))]
SomeSocketAddrClonable::Unix(x) => write!(f, "unix:{x:?}"),
#[cfg(feature = "inetd")]
SomeSocketAddrClonable::Stdio => "stdio".fmt(f),
#[cfg(feature = "multi-listener")]
SomeSocketAddrClonable::Multiple => "multiple".fmt(f),
}
}
}
impl From<SomeSocketAddr> for SomeSocketAddrClonable {
fn from(value: SomeSocketAddr) -> Self {
value.clonable()
}
}