From b8babb57dd69622dc3c71e4678341adf6472ec96 Mon Sep 17 00:00:00 2001 From: Adam Wright Date: Sun, 14 Feb 2016 18:11:04 -0800 Subject: [PATCH 1/2] Add TryClone to Client/AsyncClient --- tarpc/src/macros.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs index 6f62da1..ae441d0 100644 --- a/tarpc/src/macros.rs +++ b/tarpc/src/macros.rs @@ -265,6 +265,11 @@ macro_rules! service_inner { $fn_name($($arg: $in_),*) -> $out )* ); + + #[doc="Attempt to clone the client object. This might fail if the underlying TcpStream clone fails"] + pub fn try_clone(&self) -> ::std::io::Result { + Ok(Client(try!(self.0.try_clone()))) + } } #[doc="The client stub that makes asynchronous RPC calls to the server."] @@ -286,6 +291,11 @@ macro_rules! service_inner { $fn_name($($arg: $in_),*) -> $out )* ); + + #[doc="Attempt to clone the client object. This might fail if the underlying TcpStream clone fails"] + pub fn try_clone(&self) -> ::std::io::Result { + Ok(AsyncClient(try!(self.0.try_clone()))) + } } struct __Server(S); @@ -386,6 +396,24 @@ mod functional_test { handle.shutdown(); } + #[test] + fn try_clone() { + let handle = serve( "localhost:0", Server, test_timeout()).unwrap(); + let client1 = Client::new(handle.local_addr(), None).unwrap(); + let client2 = client1.try_clone().unwrap(); + assert_eq!(3, client1.add(1, 2).unwrap()); + assert_eq!(3, client2.add(1, 2).unwrap()); + } + + #[test] + fn async_try_clone() { + let handle = serve("localhost:0", Server, test_timeout()).unwrap(); + let client1 = AsyncClient::new(handle.local_addr(), None).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()); + } + // Tests that a server can be wrapped in an Arc; no need to run, just compile #[allow(dead_code)] fn serve_arc_server() { From 04e513309a1d37ed6e00b6b5af3b3f8499c22008 Mon Sep 17 00:00:00 2001 From: Adam Wright Date: Sun, 14 Feb 2016 19:21:22 -0800 Subject: [PATCH 2/2] Fix docstring and fully qualify Ok --- tarpc/src/macros.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs index ae441d0..6304183 100644 --- a/tarpc/src/macros.rs +++ b/tarpc/src/macros.rs @@ -266,9 +266,10 @@ macro_rules! service_inner { )* ); - #[doc="Attempt to clone the client object. This might fail if the underlying TcpStream clone fails"] + #[doc="Attempt to clone the client object. This might fail if the underlying TcpStream \ + clone fails."] pub fn try_clone(&self) -> ::std::io::Result { - Ok(Client(try!(self.0.try_clone()))) + ::std::result::Result::Ok(Client(try!(self.0.try_clone()))) } } @@ -292,9 +293,10 @@ macro_rules! service_inner { )* ); - #[doc="Attempt to clone the client object. This might fail if the underlying TcpStream clone fails"] + #[doc="Attempt to clone the client object. This might fail if the underlying TcpStream \ + clone fails."] pub fn try_clone(&self) -> ::std::io::Result { - Ok(AsyncClient(try!(self.0.try_clone()))) + ::std::result::Result::Ok(AsyncClient(try!(self.0.try_clone()))) } }