From 066d42c0e0ff1e7378052d94cc3a9625af37360d Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Sun, 7 Jan 2018 20:52:28 -0800 Subject: [PATCH] Clean up dispatch_socket!() syntax This modified syntax is meant to more closely resemble standard Rust. --- src/socket/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/socket/mod.rs b/src/socket/mod.rs index c77c6cc..a476682 100644 --- a/src/socket/mod.rs +++ b/src/socket/mod.rs @@ -79,7 +79,13 @@ pub enum Socket<'a, 'b: 'a> { } macro_rules! dispatch_socket { - ($self_:expr, |$socket:ident [$( $mut_:tt )*]| $code:expr) => ({ + ($self_:expr, |$socket:ident| $code:expr) => { + dispatch_socket!(@inner $self_, |$socket| $code); + }; + (mut $self_:expr, |$socket:ident| $code:expr) => { + dispatch_socket!(@inner mut $self_, |$socket| $code); + }; + (@inner $( $mut_:ident )* $self_:expr, |$socket:ident| $code:expr) => { match $self_ { #[cfg(feature = "socket-raw")] &$( $mut_ )* Socket::Raw(ref $( $mut_ )* $socket) => $code, @@ -91,7 +97,7 @@ macro_rules! dispatch_socket { &$( $mut_ )* Socket::Tcp(ref $( $mut_ )* $socket) => $code, &$( $mut_ )* Socket::__Nonexhaustive(_) => unreachable!() } - }) + }; } impl<'a, 'b> Socket<'a, 'b> { @@ -102,21 +108,21 @@ impl<'a, 'b> Socket<'a, 'b> { } pub(crate) fn meta(&self) -> &SocketMeta { - dispatch_socket!(self, |socket []| &socket.meta) + dispatch_socket!(self, |socket| &socket.meta) } pub(crate) fn meta_mut(&mut self) -> &mut SocketMeta { - dispatch_socket!(self, |socket [mut]| &mut socket.meta) + dispatch_socket!(mut self, |socket| &mut socket.meta) } pub(crate) fn poll_at(&self) -> Option { - dispatch_socket!(self, |socket []| socket.poll_at()) + dispatch_socket!(self, |socket| socket.poll_at()) } } impl<'a, 'b> SocketSession for Socket<'a, 'b> { fn finish(&mut self) { - dispatch_socket!(self, |socket [mut]| socket.finish()) + dispatch_socket!(mut self, |socket| socket.finish()) } }