Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
net: add unix::SocketAddr::as_abstract_name
This adds a Linux-specific `SocketAddr::as_abstract_name()` based on
stdlib `SocketAddrExt` trait (available since Rust 1.70).
The current MSRV is already 1.70.0, so this is not a breaking change.
  • Loading branch information
lucab committed Jul 29, 2025
commit 54a40d3ae6e022323a140b9fb9b9910c3e98a310
3 changes: 2 additions & 1 deletion spellcheck.dic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
306
307
&
+
<
Expand Down Expand Up @@ -184,6 +184,7 @@ mut
mutex
Mutex
Nagle
namespace
nonblocking
nondecreasing
noop
Expand Down
22 changes: 20 additions & 2 deletions tokio/src/net/unix/socketaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct SocketAddr(pub(super) std::os::unix::net::SocketAddr);
impl SocketAddr {
/// Returns `true` if the address is unnamed.
///
/// Documentation reflected in [`SocketAddr`]
/// Documentation reflected in [`SocketAddr`].
///
/// [`SocketAddr`]: std::os::unix::net::SocketAddr
pub fn is_unnamed(&self) -> bool {
Expand All @@ -21,12 +21,30 @@ impl SocketAddr {

/// Returns the contents of this address if it is a `pathname` address.
///
/// Documentation reflected in [`SocketAddr`]
/// Documentation reflected in [`SocketAddr`].
///
/// [`SocketAddr`]: std::os::unix::net::SocketAddr
pub fn as_pathname(&self) -> Option<&Path> {
self.0.as_pathname()
}

/// Returns the contents of this address if it is in the abstract namespace.
///
/// Documentation reflected in [`SocketAddrExt`].
/// The abstract namespace is a Linux-specific feature.
///
///
/// [`SocketAddrExt`]: std::os::linux::net::SocketAddrExt
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "linux", target_os = "android"))))]
pub fn as_abstract_name(&self) -> Option<&[u8]> {
#[cfg(target_os = "android")]
use std::os::android::net::SocketAddrExt;
#[cfg(target_os = "linux")]
use std::os::linux::net::SocketAddrExt;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this trait has been added in Rust 1.70, which is compatible with current MSRV:

rust-version = "1.70"


self.0.as_abstract_name()
}
}

impl fmt::Debug for SocketAddr {
Expand Down
Loading