diff --git a/tarpc/src/lib.rs b/tarpc/src/lib.rs index 3de785b..9822ecf 100644 --- a/tarpc/src/lib.rs +++ b/tarpc/src/lib.rs @@ -19,7 +19,8 @@ //! use self::my_server::*; //! use std::time::Duration; //! -//! impl my_server::Service for () { +//! struct Server; +//! impl my_server::Service for Server { //! fn hello(&self, s: String) -> String { //! format!("Hello, {}!", s) //! } @@ -30,8 +31,10 @@ //! //! fn main() { //! let addr = "127.0.0.1:9000"; -//! let shutdown = my_server::serve(addr, (), -//! Some(Duration::from_secs(30))).unwrap(); +//! let shutdown = my_server::serve(addr, +//! Server, +//! Some(Duration::from_secs(30))) +//! .unwrap(); //! let client = Client::new(addr, None).unwrap(); //! assert_eq!(3, client.add(1, 2).unwrap()); //! assert_eq!("Hello, Mom!".to_string(), diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs index 4670030..18070a5 100644 --- a/tarpc/src/macros.rs +++ b/tarpc/src/macros.rs @@ -190,6 +190,17 @@ macro_rules! rpc { )* } + impl

Service for P + where P: Send + Sync + ::std::ops::Deref + { + $( + $(#[$attr])* + fn $fn_name(&self, $($arg:$in_),*) -> $out { + Service::$fn_name(&**self, $($arg),*) + } + )* + } + define_request!($($fn_name($($in_),*))*); #[allow(non_camel_case_types)] @@ -283,7 +294,8 @@ mod test { use self::my_server::*; - impl Service for () { + struct Server; + impl Service for Server { fn hello(&self, s: Foo) -> Foo { Foo { message: format!("Hello, {}", &s.message) } } @@ -297,7 +309,7 @@ mod test { fn simple_test() { println!("Starting"); let addr = "127.0.0.1:9000"; - let shutdown = my_server::serve(addr, (), test_timeout()).unwrap(); + let shutdown = my_server::serve(addr, Server, test_timeout()).unwrap(); let client = Client::new(addr, None).unwrap(); assert_eq!(3, client.add(1, 2).unwrap()); let foo = Foo { message: "Adam".into() };