20 Commits

Author SHA1 Message Date
Tim
92f157206d Minor change rollup
* Head off imminent breakage due to https://github.com/rust-lang/rust/pull/51285.
* Fix examples and documentation to use a recently-gated feature, `proc_macro_path_invoc`.
* Update dependency versions.
2018-07-11 17:04:54 -07:00
Tim
b093db63a3 Remove usage of Cursor (#186)
* Add intellij files to .gitignore

* Remove Cursor usage when deserializing

* Don't use methods that copy into another temp buffer
2018-04-14 21:16:35 -07:00
Tim
8c3e3df47f Bump tarpc-plugins version. (#185) 2018-04-09 18:45:28 -07:00
Tim
6907c6e0a3 Merge pull request #183 from tikue/fix-breakage
Fix breakage on most recent nightly.
2018-04-09 12:28:06 -07:00
Tim Kuehn
4b5273127d Fix breakage on most recent nightly. 2018-04-08 22:16:00 -07:00
Tim
4b763e9f52 Merge pull request #180 from tikue/update-deps
Update deps and fix deprecation warnings.
2018-03-27 11:25:18 -07:00
Tim Kuehn
848eb00bea Bump version 2018-03-26 00:53:28 -07:00
Tim Kuehn
44ec68c002 Update deps 2018-03-26 00:32:40 -07:00
Tim Kuehn
b2282f9d7a Clean up code warnings 2018-03-25 23:52:36 -07:00
Tim
326f0270b9 Merge pull request #175 from imp/updates
Update dependency versions, and apply clippy suggestions.
2017-12-05 10:31:31 -08:00
Cyril Plisko
fd47a6c038 Drop more 'static lifetime 2017-12-05 07:14:34 -05:00
Cyril Plisko
77cfffaaed Drop more 'static lifetimes 2017-12-04 19:24:03 -05:00
Cyril Plisko
118893678b Update dependencies
lazy_static (0.2 -> 1.0)
bincode (0.8 -> 0.9)
2017-12-04 18:02:09 -05:00
Cyril Plisko
ae3985de46 clippy: using '.clone()' on a ref-counted pointer 2017-12-04 17:52:09 -05:00
Cyril Plisko
49f36e0b2b clippy: simplify else arm 2017-12-04 17:46:04 -05:00
Cyril Plisko
4a7082b27c clippy: unneeded dereference 2017-12-04 17:45:24 -05:00
Cyril Plisko
3aa53a06fb clippy: use .is_err() instead of destructuring Result 2017-11-23 10:04:39 +02:00
Cyril Plisko
a0afbefef4 &'static str -> &str
'static lifetime in const is default
2017-11-23 09:29:23 +02:00
Cyril Plisko
5b554f7062 itertools: update to 0.7 2017-11-23 09:18:24 +02:00
Tim
0411a90be9 Fix README link to documentation (#171)
Fixes #170
2017-11-03 13:37:26 -05:00
27 changed files with 121 additions and 111 deletions

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@ Cargo.lock
.cargo
*.swp
*.bk
tarpc.iml
.idea

View File

@@ -1,6 +1,6 @@
[package]
name = "tarpc"
version = "0.9.0"
version = "0.12.0"
authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.kuehn@gmail.com>"]
license = "MIT"
documentation = "https://docs.rs/tarpc"
@@ -15,37 +15,38 @@ description = "An RPC framework for Rust with a focus on ease of use."
travis-ci = { repository = "google/tarpc" }
[dependencies]
bincode = "0.8"
bincode = "1.0"
byteorder = "1.0"
bytes = "0.4"
cfg-if = "0.1.0"
futures = "0.1.11"
lazy_static = "0.2"
log = "0.3"
lazy_static = "1.0"
log = "0.4"
net2 = "0.2"
num_cpus = "1.0"
serde = "1.0"
serde_derive = "1.0"
tarpc-plugins = { path = "src/plugins", version = "0.2.0" }
tarpc-plugins = { path = "src/plugins", version = "0.4.0" }
thread-pool = "0.1.1"
tokio-codec = "0.1"
tokio-core = "0.1.6"
tokio-io = "0.1"
tokio-proto = "0.1.1"
tokio-service = "0.1"
# Optional dependencies
native-tls = { version = "0.1.1", optional = true }
native-tls = { version = "0.1", optional = true }
tokio-tls = { version = "0.1", optional = true }
[dev-dependencies]
chrono = "0.4"
env_logger = "0.4"
env_logger = "0.5"
futures-cpupool = "0.1"
clap = "2.0"
serde_bytes = "0.10"
[target.'cfg(target_os = "macos")'.dev-dependencies]
security-framework = "0.1"
security-framework = "0.2"
[features]
default = []

View File

@@ -11,7 +11,7 @@ tarpc is an RPC framework for rust with a focus on ease of use. Defining a
service can be done in just a few lines of code, and most of the boilerplate of
writing a server is taken care of for you.
[Documentation](https://docs.rs/tarpc)
[Documentation](https://docs.rs/crate/tarpc/)
## What is an RPC framework?
"RPC" stands for "Remote Procedure Call," a function call where the work of
@@ -37,8 +37,8 @@ arguments to tarpc fns.
Add to your `Cargo.toml` dependencies:
```toml
tarpc = "0.9.0"
tarpc-plugins = "0.2.0"
tarpc = "0.12.0"
tarpc-plugins = "0.4.0"
```
## Example: Sync
@@ -47,7 +47,7 @@ tarpc has two APIs: `sync` for blocking code and `future` for asynchronous
code. Here's how to use the sync api.
```rust
#![feature(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]
@@ -100,7 +100,7 @@ races! See the `tarpc_examples` package for more examples.
Here's the same service, implemented using futures.
```rust
#![feature(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate futures;
@@ -171,7 +171,7 @@ However, if you are working with both stream types, ensure that you use the TLS
servers and TCP clients with TCP servers.
```rust,no_run
#![feature(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate futures;

View File

@@ -1,3 +1,13 @@
## 0.10.0 (2018-04-08)
## Breaking Changes
Fixed rustc breakage in tarpc-plugins. These changes require a recent version of rustc.
## 0.10.0 (2018-03-26)
## Breaking Changes
Updates bincode to version 1.0.
## 0.9.0 (2017-09-17)
## Breaking Changes

View File

@@ -3,7 +3,7 @@
// 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(plugin, test, use_extern_macros)]
#![feature(plugin, test, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]
@@ -38,7 +38,7 @@ impl FutureService for Server {
#[cfg(test)]
#[bench]
fn latency(bencher: &mut Bencher) {
let _ = env_logger::init();
let _ = env_logger::try_init();
let mut reactor = reactor::Core::new().unwrap();
let (handle, server) = Server
.listen(

View File

@@ -3,7 +3,7 @@
// 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(inclusive_range_syntax, conservative_impl_trait, plugin, never_type, use_extern_macros)]
#![feature(plugin, never_type, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate chrono;
@@ -147,7 +147,7 @@ fn run_once(
}
fn main() {
let _ = env_logger::init();
env_logger::init();
let matches = App::new("Tarpc Concurrency")
.about(
"Demonstrates making concurrent requests to a tarpc service.",

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate env_logger;
@@ -100,7 +100,7 @@ impl publisher::FutureService for Publisher {
type SubscribeFut = Box<Future<Item = (), Error = Message>>;
fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
let clients = self.clients.clone();
let clients = Rc::clone(&self.clients);
Box::new(
subscriber::FutureClient::connect(address, client::Options::default())
.map(move |subscriber| {
@@ -117,12 +117,12 @@ impl publisher::FutureService for Publisher {
fn unsubscribe(&self, id: u32) -> Self::UnsubscribeFut {
println!("Unsubscribing {}", id);
self.clients.borrow_mut().remove(&id).unwrap();
futures::finished(()).boxed()
Box::new(futures::finished(()))
}
}
fn main() {
let _ = env_logger::init();
env_logger::init();
let mut reactor = reactor::Core::new().unwrap();
let (publisher_handle, server) = Publisher::new()
.listen(

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate futures;

View File

@@ -4,7 +4,7 @@
// This file may not be copied, modified, or distributed except according to those terms.
// required by `FutureClient` (not used directly in this example)
#![feature(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate env_logger;
@@ -14,7 +14,7 @@ extern crate tokio_core;
use add::{FutureService as AddFutureService, FutureServiceExt as AddExt};
use double::{FutureService as DoubleFutureService, FutureServiceExt as DoubleExt};
use futures::{BoxFuture, Future, Stream};
use futures::{Future, Stream};
use tarpc::future::{client, server};
use tarpc::future::client::ClientExt as Fc;
use tarpc::util::{FirstSocketAddr, Message, Never};
@@ -59,18 +59,17 @@ impl DoubleServer {
}
impl DoubleFutureService for DoubleServer {
type DoubleFut = BoxFuture<i32, Message>;
type DoubleFut = Box<Future<Item=i32, Error=Message>>;
fn double(&self, x: i32) -> Self::DoubleFut {
self.client
Box::new(self.client
.add(x, x)
.map_err(|e| e.to_string().into())
.boxed()
.map_err(|e| e.to_string().into()))
}
}
fn main() {
let _ = env_logger::init();
env_logger::init();
let mut reactor = reactor::Core::new().unwrap();
let (add, server) = AddServer
.listen(

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
extern crate env_logger;
@@ -61,7 +61,7 @@ impl DoubleSyncService for DoubleServer {
}
fn main() {
let _ = env_logger::init();
env_logger::init();
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let handle = AddServer

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]
@@ -112,7 +112,7 @@ fn bench_tcp(target: u64) {
}
fn main() {
let _ = env_logger::init();
env_logger::init();
let _ = *BUF; // To non-lazily initialize it.
bench_tcp(256 << 20);
bench_tarpc(256 << 20);

View File

@@ -3,7 +3,7 @@
// 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(plugin, use_extern_macros)]
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]
@@ -56,7 +56,7 @@ impl baz::FutureService for Baz {
}
fn main() {
let _ = env_logger::init();
env_logger::init();
let bar_client = {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {

View File

@@ -1,2 +1 @@
ideal_width = 100
reorder_imports = true

View File

@@ -90,17 +90,18 @@ enum Reactor {
impl fmt::Debug for Reactor {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
const HANDLE: &'static &'static str = &"Reactor::Handle";
const HANDLE_INNER: &'static &'static str = &"Handle { .. }";
const REMOTE: &'static &'static str = &"Reactor::Remote";
const REMOTE_INNER: &'static &'static str = &"Remote { .. }";
const HANDLE: &str = "Reactor::Handle";
const HANDLE_INNER: &str = "Handle { .. }";
const REMOTE: &str = "Reactor::Remote";
const REMOTE_INNER: &str = "Remote { .. }";
match *self {
Reactor::Handle(_) => f.debug_tuple(HANDLE).field(HANDLE_INNER).finish(),
Reactor::Remote(_) => f.debug_tuple(REMOTE).field(REMOTE_INNER).finish(),
Reactor::Handle(_) => f.debug_tuple(HANDLE).field(&HANDLE_INNER).finish(),
Reactor::Remote(_) => f.debug_tuple(REMOTE).field(&REMOTE_INNER).finish(),
}
}
}
#[doc(hidden)]
pub struct Client<Req, Resp, E>
where
@@ -159,7 +160,7 @@ where
Resp: DeserializeOwned + Send + 'static,
E: DeserializeOwned + Send + 'static,
{
let inner = Proto::new(max_payload_size).bind_client(&handle, tcp);
let inner = Proto::new(max_payload_size).bind_client(handle, tcp);
Client { inner }
}

View File

@@ -20,12 +20,12 @@ impl Tracker {
}
pub fn increment(&self) {
let _ = self.tx.send(Action::Increment);
let _ = self.tx.unbounded_send(Action::Increment);
}
pub fn decrement(&self) {
debug!("Closing connection");
let _ = self.tx.send(Action::Decrement);
let _ = self.tx.unbounded_send(Action::Decrement);
}
}

View File

@@ -127,12 +127,12 @@ impl fmt::Debug for Acceptor {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use self::Acceptor::*;
#[cfg(feature = "tls")]
const TLS: &'static &'static str = &"TlsAcceptor { .. }";
const TLS: &str = "TlsAcceptor { .. }";
match *self {
Tcp => fmt.debug_tuple("Acceptor::Tcp").finish(),
#[cfg(feature = "tls")]
Tls(_) => fmt.debug_tuple("Acceptlr::Tls").field(TLS).finish(),
Tls(_) => fmt.debug_tuple("Acceptor::Tls").field(&TLS).finish(),
}
}
}
@@ -223,18 +223,18 @@ impl Options {
impl fmt::Debug for Options {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
#[cfg(feature = "tls")]
const SOME: &'static &'static str = &"Some(_)";
const SOME: &str = "Some(_)";
#[cfg(feature = "tls")]
const NONE: &'static &'static str = &"None";
const NONE: &str = "None";
let mut debug_struct = fmt.debug_struct("Options");
#[cfg(feature = "tls")]
debug_struct.field(
"tls_acceptor",
if self.tls_acceptor.is_some() {
SOME
&SOME
} else {
NONE
&NONE
},
);
debug_struct.finish()
@@ -352,9 +352,8 @@ where
St: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
const HANDLE: &'static &'static str = &"Handle { .. }";
f.debug_struct("BindStream")
.field("handle", HANDLE)
.field("handle", &self.handle)
.field("new_service", &self.new_service)
.field("stream", &self.stream)
.finish()

View File

@@ -36,7 +36,7 @@ impl Shutdown {
/// The returned future resolves when the server is completely shut down.
pub fn shutdown(&self) -> ShutdownFuture {
let (tx, rx) = oneshot::channel();
let inner = if let Err(_) = self.tx.send(tx) {
let inner = if self.tx.unbounded_send(tx).is_err() {
trace!("Server already initiated shutdown.");
futures::Either::A(futures::ok(()))
} else {

View File

@@ -27,7 +27,7 @@
//! Example usage:
//!
//! ```
//! #![feature(plugin, use_extern_macros)]
//! #![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
//! #![plugin(tarpc_plugins)]
//!
//! #[macro_use]
@@ -71,7 +71,7 @@
//! Example usage with TLS:
//!
//! ```no-run
//! #![feature(plugin, use_extern_macros)]
//! #![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
//! #![plugin(tarpc_plugins)]
//!
//! #[macro_use]
@@ -116,7 +116,7 @@
#![deny(missing_docs, missing_debug_implementations)]
#![feature(never_type)]
#![cfg_attr(test, feature(plugin, use_extern_macros))]
#![cfg_attr(test, feature(plugin, use_extern_macros, proc_macro_path_invoc))]
#![cfg_attr(test, plugin(tarpc_plugins))]
extern crate byteorder;
@@ -130,6 +130,7 @@ extern crate log;
extern crate net2;
extern crate num_cpus;
extern crate thread_pool;
extern crate tokio_codec;
extern crate tokio_io;
#[doc(hidden)]

View File

@@ -14,7 +14,7 @@ macro_rules! as_item {
/// Rpc methods are specified, mirroring trait syntax:
///
/// ```
/// # #![feature(plugin, use_extern_macros)]
/// # #![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
/// # #![plugin(tarpc_plugins)]
/// # #[macro_use] extern crate tarpc;
/// # fn main() {}
@@ -593,7 +593,7 @@ mod functional_test {
cfg_if! {
if #[cfg(feature = "tls")] {
const DOMAIN: &'static str = "foobar.com";
const DOMAIN: &str = "foobar.com";
use tls::client::Context;
use native_tls::{Pkcs12, TlsAcceptor, TlsConnector};
@@ -634,7 +634,7 @@ mod functional_test {
let buf = include_bytes!("../test/root-ca.der");
let cert = unwrap!(Certificate::from_der(buf));
let mut connector = unwrap!(TlsConnector::builder());
connector.add_root_certificate(cert);
connector.add_root_certificate(cert).unwrap();
Context {
domain: DOMAIN.into(),
@@ -657,7 +657,6 @@ mod functional_test {
fn get_tls_client_context() -> Context {
let mut connector = unwrap!(TlsConnector::builder());
unwrap!(connector.builder_mut()
.builder_mut()
.set_ca_file("test/root-ca.pem"));
Context {
domain: DOMAIN.into(),
@@ -850,7 +849,7 @@ mod functional_test {
#[test]
fn simple() {
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, client, _) =
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
assert_eq!(3, client.add(1, 2).unwrap());
@@ -861,7 +860,7 @@ mod functional_test {
fn shutdown() {
use futures::{Async, Future};
let _ = env_logger::init();
let _ = env_logger::try_init();
let (addr, client, shutdown) =
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
assert_eq!(3, unwrap!(client.add(1, 2)));
@@ -897,7 +896,7 @@ mod functional_test {
#[test]
fn no_shutdown() {
let _ = env_logger::init();
let _ = env_logger::try_init();
let (addr, client, shutdown) =
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
assert_eq!(3, client.add(1, 2).unwrap());
@@ -913,7 +912,7 @@ mod functional_test {
#[test]
fn other_service() {
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, client, _) = unwrap!(start_server_with_sync_client::<
super::other_service::SyncClient,
Server,
@@ -989,7 +988,7 @@ mod functional_test {
#[test]
fn simple() {
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, mut reactor, client) = unwrap!(
start_server_with_async_client::<FutureClient, Server>(Server)
);
@@ -1005,7 +1004,7 @@ mod functional_test {
use futures::Future;
use tokio_core::reactor;
let _ = env_logger::init();
let _ = env_logger::try_init();
let (handle, mut reactor, server) = unwrap!(return_server::<Server>(Server));
let (tx, rx) = ::std::sync::mpsc::channel();
@@ -1027,7 +1026,7 @@ mod functional_test {
#[test]
fn concurrent() {
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, mut reactor, client) = unwrap!(
start_server_with_async_client::<FutureClient, Server>(Server)
);
@@ -1041,7 +1040,7 @@ mod functional_test {
#[test]
fn other_service() {
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, mut reactor, client) = unwrap!(start_server_with_async_client::<
super::other_service::FutureClient,
Server,
@@ -1058,7 +1057,7 @@ mod functional_test {
use future::server;
use super::FutureServiceExt;
let _ = env_logger::init();
let _ = env_logger::try_init();
let reactor = reactor::Core::new().unwrap();
let handle = Server
.listen(
@@ -1080,7 +1079,7 @@ mod functional_test {
use util::FirstSocketAddr;
use super::{FutureClient, FutureServiceExt};
let _ = env_logger::init();
let _ = env_logger::try_init();
let mut reactor = reactor::Core::new().unwrap();
let (handle, server) = Server
.listen(
@@ -1115,7 +1114,7 @@ mod functional_test {
use future::client::ClientExt;
use super::FutureServiceExt;
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, mut reactor, client) = unwrap!(
start_server_with_async_client::<FutureClient, Server>(Server)
);
@@ -1167,7 +1166,7 @@ mod functional_test {
fn error() {
use std::error::Error as E;
use self::error_service::*;
let _ = env_logger::init();
let _ = env_logger::try_init();
let (_, mut reactor, client) =
start_err_server_with_async_client::<FutureClient, ErrorServer>(ErrorServer).unwrap();

View File

@@ -1,6 +1,6 @@
[package]
name = "tarpc-plugins"
version = "0.2.0"
version = "0.4.0"
authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.kuehn@gmail.com>"]
license = "MIT"
documentation = "https://docs.rs/tarpc"
@@ -15,7 +15,7 @@ description = "Plugins for tarpc, an RPC framework for Rust with a focus on ease
travis-ci = { repository = "google/tarpc" }
[dependencies]
itertools = "0.6"
itertools = "0.7"
[lib]
plugin = true

View File

@@ -8,7 +8,7 @@ use itertools::Itertools;
use rustc_plugin::Registry;
use syntax::ast::{self, Ident, TraitRef, Ty, TyKind};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::quote::rt::Span;
use syntax::codemap::Span;
use syntax::parse::{self, token, str_lit, PResult};
use syntax::parse::parser::{Parser, PathStyle};
use syntax::symbol::Symbol;
@@ -126,7 +126,7 @@ fn ty_snake_to_camel(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacRe
convert(&mut path.segments
.last_mut()
.unwrap()
.identifier);
.ident);
MacEager::ty(P(Ty {
id: ast::DUMMY_NODE_ID,
node: TyKind::Path(None, path),
@@ -160,10 +160,8 @@ fn convert(ident: &mut Ident) -> String {
while let Some(c) = chars.next() {
if c != '_' {
camel_ty.push(c);
} else {
if let Some(c) = chars.next() {
camel_ty.extend(c.to_uppercase());
}
} else if let Some(c) = chars.next() {
camel_ty.extend(c.to_uppercase());
}
}
}

View File

@@ -3,16 +3,16 @@
// 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.
use bincode::{self, Infinite};
use byteorder::{BigEndian, ReadBytesExt};
use bincode;
use byteorder::{BigEndian, ByteOrder};
use bytes::BytesMut;
use bytes::buf::BufMut;
use serde;
use std::io::{self, Cursor};
use std::io;
use std::marker::PhantomData;
use std::mem;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_io::codec::{Encoder, Decoder, Framed};
use tokio_codec::{Encoder, Decoder, Framed};
use tokio_proto::multiplex::{ClientProto, ServerProto};
use tokio_proto::streaming::multiplex::RequestId;
@@ -34,7 +34,7 @@ enum CodecState {
impl<Encode, Decode> Codec<Encode, Decode> {
fn new(max_payload_size: u64) -> Self {
Codec {
max_payload_size: max_payload_size,
max_payload_size,
state: CodecState::Id,
_phantom_data: PhantomData,
}
@@ -66,16 +66,18 @@ where
type Error = io::Error;
fn encode(&mut self, (id, message): Self::Item, buf: &mut BytesMut) -> io::Result<()> {
let payload_size = bincode::serialized_size(&message);
let payload_size = bincode::serialized_size(&message).map_err(|serialize_err| {
io::Error::new(io::ErrorKind::Other, serialize_err)
})?;
if payload_size > self.max_payload_size {
return Err(too_big(payload_size, self.max_payload_size));
}
let message_size = 2 * mem::size_of::<u64>() + payload_size as usize;
buf.reserve(message_size);
buf.put_u64::<BigEndian>(id);
buf.put_u64_be(id);
trace!("Encoded request id = {} as {:?}", id, buf);
buf.put_u64::<BigEndian>(payload_size);
bincode::serialize_into(&mut buf.writer(), &message, Infinite)
buf.put_u64_be(payload_size);
bincode::serialize_into(&mut buf.writer(), &message)
.map_err(|serialize_err| {
io::Error::new(io::ErrorKind::Other, serialize_err)
})?;
@@ -103,9 +105,9 @@ where
}
Id => {
let mut id_buf = buf.split_to(mem::size_of::<u64>());
let id = Cursor::new(&mut id_buf).read_u64::<BigEndian>()?;
let id = BigEndian::read_u64(&*id_buf);
trace!("--> Parsed id = {} from {:?}", id, id_buf);
self.state = Len { id: id };
self.state = Len { id };
}
Len { .. } if buf.len() < mem::size_of::<u64>() => {
trace!(
@@ -116,7 +118,7 @@ where
}
Len { id } => {
let len_buf = buf.split_to(mem::size_of::<u64>());
let len = Cursor::new(len_buf).read_u64::<BigEndian>()?;
let len = BigEndian::read_u64(&*len_buf);
trace!(
"--> Parsed payload length = {}, remaining buffer length = {}",
len,
@@ -125,7 +127,7 @@ where
if len > self.max_payload_size {
return Err(too_big(len, self.max_payload_size));
}
self.state = Payload { id: id, len: len };
self.state = Payload { id, len };
}
Payload { len, .. } if buf.len() < len as usize => {
trace!(
@@ -137,7 +139,7 @@ where
}
Payload { id, len } => {
let payload = buf.split_to(len as usize);
let result = bincode::deserialize_from(&mut Cursor::new(payload), Infinite);
let result = bincode::deserialize(&payload);
// Reset the state machine because, either way, we're done processing this
// message.
self.state = Id;
@@ -178,7 +180,7 @@ where
type BindTransport = Result<Self::Transport, io::Error>;
fn bind_transport(&self, io: T) -> Self::BindTransport {
Ok(io.framed(Codec::new(self.max_payload_size)))
Ok(Framed::new(io, Codec::new(self.max_payload_size)))
}
}
@@ -194,7 +196,7 @@ where
type BindTransport = Result<Self::Transport, io::Error>;
fn bind_transport(&self, io: T) -> Self::BindTransport {
Ok(io.framed(Codec::new(self.max_payload_size)))
Ok(Framed::new(io, Codec::new(self.max_payload_size)))
}
}

View File

@@ -30,8 +30,8 @@ impl<Req, Resp, E> Clone for Client<Req, Resp, E> {
impl<Req, Resp, E> fmt::Debug for Client<Req, Resp, E> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
const PROXY: &'static &'static str = &"ClientProxy { .. }";
f.debug_struct("Client").field("proxy", PROXY).finish()
const PROXY: &str = "ClientProxy { .. }";
f.debug_struct("Client").field("proxy", &PROXY).finish()
}
}
@@ -93,11 +93,11 @@ impl Options {
impl fmt::Debug for Options {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
#[cfg(feature = "tls")]
const SOME: &'static &'static str = &"Some(_)";
const SOME: &str = "Some(_)";
#[cfg(feature = "tls")]
const NONE: &'static &'static str = &"None";
const NONE: &str = "None";
let mut f = f.debug_struct("Options");
#[cfg(feature = "tls")] f.field("tls_ctx", if self.tls_ctx.is_some() { SOME } else { NONE });
#[cfg(feature = "tls")] f.field("tls_ctx", if self.tls_ctx.is_some() { &SOME } else { &NONE });
f.finish()
}
}

View File

@@ -89,13 +89,12 @@ impl Handle {
impl fmt::Debug for Handle {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
const CORE: &'static &'static str = &"Core { .. }";
const SERVER: &'static &'static str = &"Box<Future<Item = (), Error = ()>>";
const SERVER: &str = "Box<Future<Item = (), Error = ()>>";
f.debug_struct("Handle")
.field("reactor", CORE)
.field("reactor", &self.reactor)
.field("handle", &self.handle)
.field("server", SERVER)
.field("server", &SERVER)
.finish()
}
}

View File

@@ -39,10 +39,10 @@ pub mod client {
impl fmt::Debug for Context {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
const TLS_CONNECTOR: &'static &'static str = &"TlsConnector { .. }";
const TLS_CONNECTOR: &str = "TlsConnector { .. }";
f.debug_struct("Context")
.field("domain", &self.domain)
.field("tls_connector", TLS_CONNECTOR)
.field("tls_connector", &TLS_CONNECTOR)
.finish()
}
}