Extend snake_to_camel plugin to replace {} in the doc string with the original snake-cased ident. (#50)

* Extend snake_to_camel plugin to replace {} in the doc string with the origin snake-cased ident.

Also, track tokio-rs master.

This is really ad-hoc, undiscoverable, and unintuitive, but there's no way to programmatically create doc strings
in regular code, and I want to produce better doc strings for the associated types.

Given `fn foo_bar`:

Before: `/// The type of future returned by the function of the same name.`
After: ``/// The type of future returned by `{}`.``
    => `/// The type of future returned by foo_bar.`

* Fix some docs

* Use a helper fn on pipeline::Frame instead of handrolled match.

* Don't hide docs for ClientFuture.

It's exposed in the Connect impl of FutureService -- the tradeoff for not generating *another* item -- and hiding it breaks doc links.

* Formatting

* Rename snake_to_camel plugin => tarpc-plugins

* Update README

* Mangle a lot of names in macro expansion.

To lower the chance of any issues, prefix idents in service expansion with __tarpc_service.
In future_enum, prefix with __future_enum. The pattern is basically __macro_name_ident.

Any imported enum variant will conflict with a let binding or a function arg, so we basically
can't use any generic idents at all. Example:

    enum Req { request(..) }
    use self::Req::request;

    fn make_request(request: Request) { ... }

                    ^^^^^^^ conflict here

Additionally, suffix generated associated types with Fut to avoid conflicts with camelcased rpcs.
Why someone would do that, I don't know, but we shouldn't allow that wart.
This commit is contained in:
Tim
2016-09-14 01:19:24 -07:00
committed by GitHub
parent 54017839d1
commit be5f55c5f6
20 changed files with 422 additions and 381 deletions

View File

@@ -4,15 +4,15 @@
// This file may not be copied, modified, or distributed except according to those terms.
#![feature(conservative_impl_trait, plugin)]
#![plugin(snake_to_camel)]
#![plugin(tarpc_plugins)]
#[macro_use]
extern crate tarpc;
extern crate futures;
use futures::{BoxFuture, Future};
use add::{FutureService as AddService, FutureServiceExt as AddExt};
use double::{FutureService as DoubleService, FutureServiceExt as DoubleExt};
use add::{FutureService as AddFutureService, FutureServiceExt as AddExt};
use double::{FutureService as DoubleFutureService, FutureServiceExt as DoubleExt};
use tarpc::util::{Never, Message};
use tarpc::future::Connect as Fc;
use tarpc::sync::Connect as Sc;
@@ -36,10 +36,10 @@ pub mod double {
#[derive(Clone)]
struct AddServer;
impl AddService for AddServer {
type Add = futures::Finished<i32, Never>;
impl AddFutureService for AddServer {
type AddFut = futures::Finished<i32, Never>;
fn add(&self, x: i32, y: i32) -> Self::Add {
fn add(&self, x: i32, y: i32) -> Self::AddFut {
futures::finished(x + y)
}
}
@@ -49,10 +49,10 @@ struct DoubleServer {
client: add::FutureClient,
}
impl DoubleService for DoubleServer {
type Double = BoxFuture<i32, Message>;
impl DoubleFutureService for DoubleServer {
type DoubleFut = BoxFuture<i32, Message>;
fn double(&self, x: i32) -> Self::Double {
fn double(&self, x: i32) -> Self::DoubleFut {
self.client
.add(&x, &x)
.map_err(|e| e.to_string().into())
@@ -61,10 +61,10 @@ impl DoubleService for DoubleServer {
}
fn main() {
let add = AddServer.listen("localhost:0").unwrap();
let add = AddServer.listen("localhost:0").wait().unwrap();
let add_client = add::FutureClient::connect(add.local_addr()).wait().unwrap();
let double = DoubleServer { client: add_client };
let double = double.listen("localhost:0").unwrap();
let double = double.listen("localhost:0").wait().unwrap();
let double_client = double::SyncClient::connect(double.local_addr()).unwrap();
for i in 0..5 {