From be61d987b4e99a38f244d746391b352c913a7f09 Mon Sep 17 00:00:00 2001 From: Kotauskas Date: Sat, 23 Mar 2024 19:01:52 +0300 Subject: [PATCH] Make `impmod!` look nicer --- src/local_socket/listener/enum.rs | 4 +--- src/local_socket/name.rs | 4 +--- src/local_socket/stream/enum.rs | 5 +---- src/local_socket/tokio/listener/enum.rs | 8 +++----- src/local_socket/tokio/stream/enum.rs | 4 +--- src/macros.rs | 6 +++++- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/local_socket/listener/enum.rs b/src/local_socket/listener/enum.rs index 144a48e..364b582 100644 --- a/src/local_socket/listener/enum.rs +++ b/src/local_socket/listener/enum.rs @@ -6,9 +6,7 @@ use {crate::os::unix::uds_local_socket as uds_impl, std::os::unix::prelude::*}; #[cfg(windows)] use {crate::os::windows::named_pipe::local_socket as np_impl, std::os::windows::prelude::*}; -impmod! {local_socket::dispatch_sync, - self, -} +impmod! {local_socket::dispatch_sync} mkenum!( /// Local socket server, listening for connections. diff --git a/src/local_socket/name.rs b/src/local_socket/name.rs index b4a2ef4..2342a4a 100644 --- a/src/local_socket/name.rs +++ b/src/local_socket/name.rs @@ -4,9 +4,7 @@ use std::{ fmt::Debug, }; -impmod! {local_socket::name, - is_namespaced, -} +impmod! {local_socket::name, is_namespaced} // TODO maybe emulate NS on FS-only via tmpfs? // TODO better PartialEq diff --git a/src/local_socket/stream/enum.rs b/src/local_socket/stream/enum.rs index e3dcd6f..96cbcc2 100644 --- a/src/local_socket/stream/enum.rs +++ b/src/local_socket/stream/enum.rs @@ -9,10 +9,7 @@ use {crate::os::unix::uds_local_socket as uds_impl, std::os::unix::prelude::*}; #[cfg(windows)] use {crate::os::windows::named_pipe::local_socket as np_impl, std::os::windows::prelude::*}; -// FIXME awkward macro syntax -impmod! {local_socket::dispatch_sync, - self, -} +impmod! { local_socket::dispatch_sync } macro_rules! dispatch_read { (@iw $ty:ident) => { diff --git a/src/local_socket/tokio/listener/enum.rs b/src/local_socket/tokio/listener/enum.rs index 8a9772a..3f6a15f 100644 --- a/src/local_socket/tokio/listener/enum.rs +++ b/src/local_socket/tokio/listener/enum.rs @@ -6,9 +6,7 @@ use std::io; #[cfg(unix)] use {crate::os::unix::uds_local_socket::tokio as uds_impl, std::os::unix::prelude::*}; -impmod! {local_socket::dispatch_tokio, - self, -} +impmod! { local_socket::dispatch_tokio as dispatch } // TODO borrowed split in examples @@ -112,11 +110,11 @@ impl r#trait::Listener for Listener { #[inline] fn bind(name: Name<'_>) -> io::Result { - dispatch_tokio::bind(name) + dispatch::bind(name) } #[inline] fn bind_without_name_reclamation(name: Name<'_>) -> io::Result { - dispatch_tokio::bind_without_name_reclamation(name) + dispatch::bind_without_name_reclamation(name) } #[inline] async fn accept(&self) -> io::Result { diff --git a/src/local_socket/tokio/stream/enum.rs b/src/local_socket/tokio/stream/enum.rs index 08880dd..be2f599 100644 --- a/src/local_socket/tokio/stream/enum.rs +++ b/src/local_socket/tokio/stream/enum.rs @@ -13,9 +13,7 @@ use { crate::os::windows::named_pipe::local_socket::tokio as np_impl, std::os::windows::prelude::*, }; -impmod! {local_socket::dispatch_tokio, - self as dispatch, -} +impmod! { local_socket::dispatch_tokio as dispatch } macro_rules! dispatch_read { (@iw $ty:ident) => { diff --git a/src/macros.rs b/src/macros.rs index 6d24802..6f2edfe 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,7 +1,11 @@ #![allow(unused_macros)] // TODO more internal docs -macro_rules! impmod { // TODO remove +/// Dispatches to a symmetrically named submodule in the target OS module. +macro_rules! impmod { + ($($osmod:ident)::+ $(as $into:ident)?) => { + impmod!($($osmod)::+, self $(as $into)?); + }; ($($osmod:ident)::+, $($orig:ident $(as $into:ident)?),* $(,)?) => { #[cfg(unix)] use $crate::os::unix::$($osmod)::+::{$($orig $(as $into)?,)*};