mirror of
https://github.com/OMGeeky/tarpc.git
synced 2025-12-31 00:21:51 +01:00
* 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.
79 lines
1.8 KiB
Rust
79 lines
1.8 KiB
Rust
// Copyright 2016 Google Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
|
// This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
#![feature(conservative_impl_trait, plugin)]
|
|
#![plugin(tarpc_plugins)]
|
|
|
|
#[macro_use]
|
|
extern crate log;
|
|
#[macro_use]
|
|
extern crate tarpc;
|
|
extern crate bincode;
|
|
extern crate env_logger;
|
|
extern crate futures;
|
|
|
|
use bar::FutureServiceExt as BarExt;
|
|
use baz::FutureServiceExt as BazExt;
|
|
use futures::Future;
|
|
use tarpc::util::Never;
|
|
use tarpc::sync::Connect;
|
|
|
|
mod bar {
|
|
service! {
|
|
rpc bar(i: i32) -> i32;
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
struct Bar;
|
|
impl bar::FutureService for Bar {
|
|
type BarFut = futures::Finished<i32, Never>;
|
|
|
|
fn bar(&self, i: i32) -> Self::BarFut {
|
|
futures::finished(i)
|
|
}
|
|
}
|
|
|
|
mod baz {
|
|
service! {
|
|
rpc baz(s: String) -> String;
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
struct Baz;
|
|
impl baz::FutureService for Baz {
|
|
type BazFut = futures::Finished<String, Never>;
|
|
|
|
fn baz(&self, s: String) -> Self::BazFut {
|
|
futures::finished(format!("Hello, {}!", s))
|
|
}
|
|
}
|
|
|
|
macro_rules! pos {
|
|
() => (concat!(file!(), ":", line!()))
|
|
}
|
|
|
|
fn main() {
|
|
let _ = env_logger::init();
|
|
let bar = Bar.listen("localhost:0").wait().unwrap();
|
|
let baz = Baz.listen("localhost:0").wait().unwrap();
|
|
let bar_client = bar::SyncClient::connect(bar.local_addr()).unwrap();
|
|
let baz_client = baz::SyncClient::connect(baz.local_addr()).unwrap();
|
|
|
|
info!("Result: {:?}", bar_client.bar(&17));
|
|
|
|
let total = 20;
|
|
for i in 1..(total + 1) {
|
|
if i % 2 == 0 {
|
|
info!("Result 1: {:?}", bar_client.bar(&i));
|
|
} else {
|
|
info!("Result 2: {:?}", baz_client.baz(&i.to_string()));
|
|
}
|
|
}
|
|
|
|
info!("Done.");
|
|
}
|