diff --git a/README.md b/README.md index 6f1db32..3377d31 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ fn main() { } ``` -The `rpc!` macro generates a module in the current module. In the above example, the module is named `hello_service`. This module will contain a `Client` type, a `Service` trait, and a `serve` function. `serve` can be used to start a server listening on a tcp port. A `Client` can connect to such a service. Any type implementing the `Service` trait can be passed to `serve`. These generated types are specific to the echo service, and make it easy and ergonomic to write servers without dealing with sockets or serialization directly. See the tarpc_examples package for more sophisticated examples. +The `rpc!` macro generates a module in the current module. In the above example, the module is named `hello_service`. This module will contain a `Client` type, a `Service` trait, and a `serve` function. `serve` can be used to start a server listening on a tcp port. A `Client` can connect to such a service. Any type implementing the `Service` trait can be passed to `serve`. Any doc attributes on rpc items in the `service { }` block will appear as documentation on both the Service trait methods as well as on the Client's stub methods. These generated types are specific to the echo service, and make it easy and ergonomic to write servers without dealing with sockets or serialization directly. See the tarpc_examples package for more sophisticated examples. ## Planned Improvements (actively being worked on) diff --git a/tarpc/src/lib.rs b/tarpc/src/lib.rs index 24eccd0..2a71330 100644 --- a/tarpc/src/lib.rs +++ b/tarpc/src/lib.rs @@ -3,7 +3,6 @@ //! Example usage: //! //! ``` -//! # #![feature(custom_derive)] //! # #![feature(custom_derive, plugin)] //! # #![plugin(serde_macros)] //! # #[macro_use] extern crate tarpc; diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs index b04feea..4516575 100644 --- a/tarpc/src/macros.rs +++ b/tarpc/src/macros.rs @@ -2,18 +2,25 @@ macro_rules! as_item { ($i:item) => {$i} } // Required because if-let can't be used with irrefutable patterns, so it needs -// to be special -// cased. +// to be special cased. #[macro_export] -macro_rules! request_fns { - ($fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty) => ( +macro_rules! client_stubs { + ( + { $(#[$attr:meta])* } + $fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty + ) => ( + $(#[$attr])* pub fn $fn_name(&self, $($arg: $in_),*) -> $crate::Result<$out> { let reply = try!((self.0).rpc(&request_variant!($fn_name $($arg),*))); let __Reply::$fn_name(reply) = reply; Ok(reply) } ); - ($( $fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty)*) => ( $( + ($( + { $(#[$attr:meta])* } + $fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty + )*) => ( $( + $(#[$attr])* pub fn $fn_name(&self, $($arg: $in_),*) -> $crate::Result<$out> { let reply = try!((self.0).rpc(&request_variant!($fn_name $($arg),*))); if let __Reply::$fn_name(reply) = reply { @@ -133,7 +140,12 @@ macro_rules! rpc { Ok(Client(inner)) } - request_fns!($($fn_name($($arg: $in_),*) -> $out)*); + client_stubs!( + $( + { $(#[$attr])* } + $fn_name($($arg: $in_),*) -> $out + )* + ); } struct __Server(S);