Skip to content

Commit

Permalink
net: add conversions for unix SocketAddr (#6868)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmathewson authored Sep 25, 2024
1 parent 09bc9a0 commit 623928e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tokio/src/net/unix/socketaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

0 comments on commit 623928e

Please sign in to comment.