mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-02 01:20:10 +01:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
//! Example usage:
|
||||
//!
|
||||
//! ```
|
||||
//! # #![feature(custom_derive)]
|
||||
//! # #![feature(custom_derive, plugin)]
|
||||
//! # #![plugin(serde_macros)]
|
||||
//! # #[macro_use] extern crate tarpc;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user