From 6273ebefa7254bea1d4923b52ed73eb9a939d414 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Thu, 25 Feb 2016 00:04:35 -0800 Subject: [PATCH] rustfmt --- tarpc/src/macros.rs | 40 +++++++++++++++++++++--------------- tarpc/src/protocol/client.rs | 18 ++++++++-------- tarpc/src/protocol/mod.rs | 8 ++------ tarpc/src/protocol/server.rs | 17 +++++++-------- tarpc/src/transport/mod.rs | 6 ++---- tarpc/src/transport/tcp.rs | 6 ++---- tarpc/src/transport/unix.rs | 6 ++---- 7 files changed, 50 insertions(+), 51 deletions(-) diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs index f2aaa0b..00399c7 100644 --- a/tarpc/src/macros.rs +++ b/tarpc/src/macros.rs @@ -261,7 +261,7 @@ macro_rules! service { #[doc(hidden)] #[macro_export] macro_rules! service_inner { - // Pattern for when the next rpc has an implicit unit return type +// Pattern for when the next rpc has an implicit unit return type ( { $(#[$attr:meta])* @@ -280,7 +280,7 @@ macro_rules! service_inner { rpc $fn_name( $( $arg : $in_ ),* ) -> (); } }; - // Pattern for when the next rpc has an explicit return type +// Pattern for when the next rpc has an explicit return type ( { $(#[$attr:meta])* @@ -299,7 +299,7 @@ macro_rules! service_inner { rpc $fn_name( $( $arg : $in_ ),* ) -> $out; } }; - // Pattern when all return types have been expanded +// Pattern when all return types have been expanded ( { } // none left to expand $( @@ -315,8 +315,11 @@ macro_rules! service_inner { )* #[doc="Spawn a running service."] - fn spawn(self, transport: T) - -> $crate::Result<$crate::protocol::ServeHandle<::Dialer>> + fn spawn(self, + transport: T) + -> $crate::Result< + $crate::protocol::ServeHandle< + ::Dialer>> where T: $crate::transport::Transport, Self: 'static, { @@ -324,13 +327,18 @@ macro_rules! service_inner { } #[doc="Spawn a running service."] - fn spawn_with_config(self, transport: T, config: $crate::Config) - -> $crate::Result<$crate::protocol::ServeHandle<::Dialer>> + fn spawn_with_config(self, + transport: T, + config: $crate::Config) + -> $crate::Result< + $crate::protocol::ServeHandle< + ::Dialer>> where T: $crate::transport::Transport, Self: 'static, { let server = __Server(self); - let handle = try!($crate::protocol::Serve::spawn_with_config(server, transport, config)); + let result = $crate::protocol::Serve::spawn_with_config(server, transport, config); + let handle = try!(result); ::std::result::Result::Ok(handle) } } @@ -386,8 +394,9 @@ macro_rules! service_inner { #[allow(unused)] #[doc="The client stub that makes RPC calls to the server."] - pub struct Client($crate::protocol::Client<__Request, __Reply, S>) - where S: $crate::transport::Stream; + pub struct Client( + $crate::protocol::Client<__Request, __Reply, S> + ) where S: $crate::transport::Stream; impl Client where S: $crate::transport::Stream @@ -428,8 +437,9 @@ macro_rules! service_inner { #[allow(unused)] #[doc="The client stub that makes asynchronous RPC calls to the server."] - pub struct AsyncClient($crate::protocol::Client<__Request, __Reply, S>) - where S: $crate::transport::Stream; + pub struct AsyncClient( + $crate::protocol::Client<__Request, __Reply, S> + ) where S: $crate::transport::Stream; impl AsyncClient where S: $crate::transport::Stream { @@ -583,10 +593,8 @@ mod functional_test { let temp_dir = tempdir::TempDir::new("tarpc").unwrap(); let temp_file = temp_dir.path() .join("async_try_clone_unix.tmp"); - let handle = Server.spawn_with_config(UnixTransport(temp_file), - Config::default()).unwrap(); - let client1 = AsyncClient::with_config(handle.dialer(), - Config::default()).unwrap(); + let handle = Server.spawn(UnixTransport(temp_file)).unwrap(); + let client1 = AsyncClient::new(handle.dialer()).unwrap(); let client2 = client1.try_clone().unwrap(); assert_eq!(3, client1.add(1, 2).get().unwrap()); assert_eq!(3, client2.add(1, 2).get().unwrap()); diff --git a/tarpc/src/protocol/client.rs b/tarpc/src/protocol/client.rs index b0bea70..dd2ed56 100644 --- a/tarpc/src/protocol/client.rs +++ b/tarpc/src/protocol/client.rs @@ -18,7 +18,7 @@ use transport::{Dialer, Stream}; /// A client stub that connects to a server to run rpcs. pub struct Client where Request: serde::ser::Serialize, - S: Stream, + S: Stream { // The guard is in an option so it can be joined in the drop fn reader_guard: Arc>>, @@ -30,12 +30,12 @@ pub struct Client impl Client where Request: serde::ser::Serialize + Send + 'static, Reply: serde::de::Deserialize + Send + 'static, - S: Stream, + S: Stream { /// Create a new client that connects to `addr`. The client uses the given timeout /// for both reads and writes. pub fn new(dialer: D) -> io::Result - where D: Dialer, + where D: Dialer { Self::with_config(dialer, Config::default()) } @@ -43,7 +43,7 @@ impl Client /// Create a new client that connects to `addr`. The client uses the given timeout /// for both reads and writes. pub fn with_config(dialer: D, config: Config) -> io::Result - where D: Dialer, + where D: Dialer { let stream = try!(dialer.dial()); try!(stream.set_read_timeout(config.timeout)); @@ -105,7 +105,7 @@ impl Client impl Drop for Client where Request: serde::ser::Serialize, - S: Stream, + S: Stream { fn drop(&mut self) { debug!("Dropping Client."); @@ -193,11 +193,11 @@ impl RpcFutures { } fn write(outbound: Receiver<(Request, Sender>)>, - requests: Arc>>, - stream: S) + requests: Arc>>, + stream: S) where Request: serde::Serialize, Reply: serde::Deserialize, - S: Stream, + S: Stream { let mut next_id = 0; let mut stream = BufWriter::new(stream); @@ -248,7 +248,7 @@ fn write(outbound: Receiver<(Request, Sender>)> fn read(requests: Arc>>, stream: S) where Reply: serde::Deserialize, - S: Stream, + S: Stream { let mut stream = BufReader::new(stream); loop { diff --git a/tarpc/src/protocol/mod.rs b/tarpc/src/protocol/mod.rs index f995ace..df55f32 100644 --- a/tarpc/src/protocol/mod.rs +++ b/tarpc/src/protocol/mod.rs @@ -181,9 +181,7 @@ mod test { let _ = env_logger::init(); let server = Arc::new(Server::new()); let serve_handle = server.spawn_with_config(TcpTransport("localhost:0"), - Config { - timeout: Some(Duration::new(0, 10)), - }) + Config { timeout: Some(Duration::new(0, 10)) }) .unwrap(); let client: Client<(), u64, _> = Client::new(serve_handle.dialer()).unwrap(); let thread = thread::spawn(move || serve_handle.shutdown()); @@ -196,9 +194,7 @@ mod test { let _ = env_logger::init(); let server = Arc::new(Server::new()); let serve_handle = server.spawn_with_config(TcpTransport("localhost:0"), - Config { - timeout: test_timeout(), - }) + Config { timeout: test_timeout() }) .unwrap(); let client: Arc> = Arc::new(Client::new(serve_handle.dialer()).unwrap()); client.rpc(()).unwrap(); diff --git a/tarpc/src/protocol/server.rs b/tarpc/src/protocol/server.rs index e7251ce..0a2523f 100644 --- a/tarpc/src/protocol/server.rs +++ b/tarpc/src/protocol/server.rs @@ -17,7 +17,7 @@ use transport::tcp::TcpDialer; struct ConnectionHandler<'a, S, St> where S: Serve, - St: Stream, + St: Stream { read_stream: BufReader, write_stream: BufWriter, @@ -27,7 +27,7 @@ struct ConnectionHandler<'a, S, St> impl<'a, S, St> ConnectionHandler<'a, S, St> where S: Serve, - St: Stream, + St: Stream { fn handle_conn<'b>(&'b mut self, scope: &Scope<'b>) -> Result<()> { let ConnectionHandler { @@ -219,19 +219,20 @@ pub trait Serve: Send + Sync + Sized { fn serve(&self, request: Self::Request) -> Self::Reply; /// spawn - fn spawn(self, transport: T) - -> io::Result::Dialer>> + fn spawn(self, transport: T) -> io::Result::Dialer>> where T: Transport, - Self: 'static, + Self: 'static { self.spawn_with_config(transport, Config::default()) } /// spawn - fn spawn_with_config(self, transport: T, config: Config) - -> io::Result::Dialer>> + fn spawn_with_config(self, + transport: T, + config: Config) + -> io::Result::Dialer>> where T: Transport, - Self: 'static, + Self: 'static { let listener = try!(transport.bind()); let dialer = try!(listener.dialer()); diff --git a/tarpc/src/transport/mod.rs b/tarpc/src/transport/mod.rs index fdb83ef..41119fc 100644 --- a/tarpc/src/transport/mod.rs +++ b/tarpc/src/transport/mod.rs @@ -21,9 +21,7 @@ pub trait Listener: Send + 'static { fn dialer(&self) -> io::Result; /// Iterate over incoming connections. fn incoming(&self) -> Incoming { - Incoming { - listener: self, - } + Incoming { listener: self } } } @@ -62,7 +60,7 @@ pub trait Dialer { } impl Dialer for P - where P: ::std::ops::Deref, + where P: ::std::ops::Deref, D: Dialer + 'static { type Stream = D::Stream; diff --git a/tarpc/src/transport/tcp.rs b/tarpc/src/transport/tcp.rs index a5b78e7..f7e078d 100644 --- a/tarpc/src/transport/tcp.rs +++ b/tarpc/src/transport/tcp.rs @@ -45,8 +45,7 @@ impl super::Stream for TcpStream { } /// Connects to a socket address. -pub struct TcpDialer(pub A) - where A: ToSocketAddrs; +pub struct TcpDialer(pub A) where A: ToSocketAddrs; impl super::Dialer for TcpDialer where A: ToSocketAddrs { @@ -55,8 +54,7 @@ impl super::Dialer for TcpDialer TcpStream::connect(&self.0) } } -impl super::Dialer for str -{ +impl super::Dialer for str { type Stream = TcpStream; fn dial(&self) -> io::Result { TcpStream::connect(self) diff --git a/tarpc/src/transport/unix.rs b/tarpc/src/transport/unix.rs index 8571ee5..1e2e7ad 100644 --- a/tarpc/src/transport/unix.rs +++ b/tarpc/src/transport/unix.rs @@ -4,8 +4,7 @@ use std::time::Duration; use unix_socket::{UnixListener, UnixStream}; /// A transport for unix sockets. -pub struct UnixTransport

(pub P) - where P: AsRef; +pub struct UnixTransport

(pub P) where P: AsRef; impl

super::Transport for UnixTransport

where P: AsRef @@ -17,8 +16,7 @@ impl

super::Transport for UnixTransport

} /// Connects to a unix socket address. -pub struct UnixDialer

(pub P) - where P: AsRef; +pub struct UnixDialer

(pub P) where P: AsRef; impl

super::Dialer for UnixDialer

where P: AsRef