From 623928e371e7c90df1cfdb6b19fe7e20b75b1377 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 25 Sep 2024 09:56:52 -0400 Subject: [PATCH] net: add conversions for unix `SocketAddr` (#6868) --- tokio/src/net/unix/socketaddr.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tokio/src/net/unix/socketaddr.rs b/tokio/src/net/unix/socketaddr.rs index 62ed4294d45..063f4c53faf 100644 --- a/tokio/src/net/unix/socketaddr.rs +++ b/tokio/src/net/unix/socketaddr.rs @@ -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 for SocketAddr { + fn from(value: std::os::unix::net::SocketAddr) -> Self { + SocketAddr(value) + } +} + +impl From for std::os::unix::net::SocketAddr { + fn from(value: SocketAddr) -> Self { + value.0 + } +}