net: add conversions for unix SocketAddr (#6868)

This commit is contained in:
Nick Mathewson
2024-09-25 13:56:52 +00:00
committed by GitHub
parent 09bc9a05e4
commit 623928e371
+16
View File
@@ -2,6 +2,10 @@ use std::fmt;
use std::path::Path;
/// An address associated with a Tokio Unix socket.
///
/// This type is a thin wrapper around [`std::os::unix::net::SocketAddr`]. You
/// can convert to and from the standard library `SocketAddr` type using the
/// [`From`] trait.
pub struct SocketAddr(pub(super) std::os::unix::net::SocketAddr);
impl SocketAddr {
@@ -29,3 +33,15 @@ impl fmt::Debug for SocketAddr {
self.0.fmt(fmt)
}
}
impl From<std::os::unix::net::SocketAddr> for SocketAddr {
fn from(value: std::os::unix::net::SocketAddr) -> Self {
SocketAddr(value)
}
}
impl From<SocketAddr> for std::os::unix::net::SocketAddr {
fn from(value: SocketAddr) -> Self {
value.0
}
}