Put doc attributes defined on rpc methods on both the Service trait fns as well as the Client method stubs.

This commit is contained in:
Tim Kuehn
2016-01-16 16:19:11 -08:00
parent e54a9df152
commit 80fb9922cd
3 changed files with 19 additions and 8 deletions

View File

@@ -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)

View File

@@ -3,7 +3,6 @@
//! Example usage:
//!
//! ```
//! # #![feature(custom_derive)]
//! # #![feature(custom_derive, plugin)]
//! # #![plugin(serde_macros)]
//! # #[macro_use] extern crate tarpc;

View File

@@ -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: 'static + Service>(S);