diff --git a/Cargo.toml b/Cargo.toml index d253ce8..7533f07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tarpc" -version = "0.7.3" +version = "0.8.0" authors = ["Adam Wright ", "Tim Kuehn "] license = "MIT" documentation = "https://docs.rs/tarpc" @@ -15,7 +15,7 @@ description = "An RPC framework for Rust with a focus on ease of use." travis-ci = { repository = "google/tarpc" } [dependencies] -bincode = "1.0.0-alpha6" +bincode = "0.8" byteorder = "1.0" bytes = "0.4" cfg-if = "0.1.0" @@ -24,8 +24,8 @@ lazy_static = "0.2" log = "0.3" net2 = "0.2" num_cpus = "1.0" -serde = "0.9" -serde_derive = "0.9" +serde = "1.0" +serde_derive = "1.0" tarpc-plugins = { path = "src/plugins", version = "0.1.1" } thread-pool = "0.1.1" tokio-core = "0.1.6" @@ -42,6 +42,7 @@ chrono = "0.3" env_logger = "0.3" futures-cpupool = "0.1" clap = "2.0" +serde_bytes = "0.10" [target.'cfg(target_os = "macos")'.dev-dependencies] security-framework = "0.1" diff --git a/RELEASES.md b/RELEASES.md index 153e3ce..11c0093 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,11 @@ +## 0.8.0 (2017-05-05) + +## Breaking Changes +This release updates tarpc to use serde 1.0. +As such, users must also update to use serde 1.0. +The serde 1.0 [release notes](https://github.com/serde-rs/serde/releases/tag/v1.0.0) +detail migration paths. + ## 0.7.3 (2017-04-26) This release removes the `Sync` bound on RPC args for both sync and future diff --git a/examples/concurrency.rs b/examples/concurrency.rs index 807f4cf..202b366 100644 --- a/examples/concurrency.rs +++ b/examples/concurrency.rs @@ -12,7 +12,7 @@ extern crate env_logger; extern crate futures; #[macro_use] extern crate log; -extern crate serde; +extern crate serde_bytes; #[macro_use] extern crate tarpc; extern crate tokio_core; @@ -31,7 +31,7 @@ use tarpc::util::{FirstSocketAddr, Never}; use tokio_core::reactor; service! { - rpc read(size: u32) -> serde::bytes::ByteBuf; + rpc read(size: u32) -> serde_bytes::ByteBuf; } #[derive(Clone)] @@ -50,7 +50,7 @@ impl Server { } impl FutureService for Server { - type ReadFut = CpuFuture; + type ReadFut = CpuFuture; fn read(&self, size: u32) -> Self::ReadFut { let request_number = self.request_count.fetch_add(1, Ordering::SeqCst); diff --git a/examples/throughput.rs b/examples/throughput.rs index c757506..823041d 100644 --- a/examples/throughput.rs +++ b/examples/throughput.rs @@ -12,12 +12,11 @@ extern crate lazy_static; extern crate tarpc; extern crate env_logger; extern crate futures; -extern crate serde; +extern crate serde_bytes; extern crate tokio_core; use std::io::{Read, Write, stdout}; use std::net; -use std::sync::Arc; use std::sync::mpsc; use std::thread; use std::time; @@ -27,7 +26,7 @@ use tarpc::util::{FirstSocketAddr, Never}; use tokio_core::reactor; lazy_static! { - static ref BUF: Arc = Arc::new(gen_vec(CHUNK_SIZE as usize).into()); + static ref BUF: serde_bytes::ByteBuf = gen_vec(CHUNK_SIZE as usize).into(); } fn gen_vec(size: usize) -> Vec { @@ -39,14 +38,14 @@ fn gen_vec(size: usize) -> Vec { } service! { - rpc read() -> Arc; + rpc read() -> serde_bytes::ByteBuf; } #[derive(Clone)] struct Server; impl FutureService for Server { - type ReadFut = Result, Never>; + type ReadFut = Result; fn read(&self) -> Self::ReadFut { Ok(BUF.clone()) diff --git a/src/errors.rs b/src/errors.rs index 1bc1512..9714b34 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -29,7 +29,7 @@ pub enum Error { App(E), } -impl fmt::Display for Error { +impl<'a, E: StdError + Deserialize<'a> + Serialize + Send + 'static> fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Error::ResponseDeserialize(ref e) => write!(f, r#"{}: "{}""#, self.description(), e), @@ -40,7 +40,7 @@ impl fmt::Display for Er } } -impl StdError for Error { +impl<'a, E: StdError + Deserialize<'a> + Serialize + Send + 'static> StdError for Error { fn description(&self) -> &str { match *self { Error::ResponseDeserialize(_) => "The client failed to deserialize the response.", diff --git a/src/future/client.rs b/src/future/client.rs index a6dd674..02e5a25 100644 --- a/src/future/client.rs +++ b/src/future/client.rs @@ -7,7 +7,8 @@ use {REMOTE, bincode}; use future::server::Response; use futures::{self, Future, future}; use protocol::Proto; -use serde::{Deserialize, Serialize}; +use serde::Serialize; +use serde::de::DeserializeOwned; use std::fmt; use std::io; use std::net::SocketAddr; @@ -103,16 +104,16 @@ impl fmt::Debug for Reactor { #[doc(hidden)] pub struct Client where Req: Serialize + 'static, - Resp: Deserialize + 'static, - E: Deserialize + 'static + Resp: DeserializeOwned + 'static, + E: DeserializeOwned + 'static { inner: ClientService>>, } impl Clone for Client where Req: Serialize + 'static, - Resp: Deserialize + 'static, - E: Deserialize + 'static + Resp: DeserializeOwned + 'static, + E: DeserializeOwned + 'static { fn clone(&self) -> Self { Client { inner: self.inner.clone() } @@ -121,8 +122,8 @@ impl Clone for Client impl Service for Client where Req: Serialize + Send + 'static, - Resp: Deserialize + Send + 'static, - E: Deserialize + Send + 'static + Resp: DeserializeOwned + Send + 'static, + E: DeserializeOwned + Send + 'static { type Request = Req; type Response = Resp; @@ -143,13 +144,13 @@ impl Service for Client impl Client where Req: Serialize + 'static, - Resp: Deserialize + 'static, - E: Deserialize + 'static + Resp: DeserializeOwned + 'static, + E: DeserializeOwned + 'static { fn bind(handle: &reactor::Handle, tcp: StreamType, max_payload_size: u64) -> Self where Req: Serialize + Send + 'static, - Resp: Deserialize + Send + 'static, - E: Deserialize + Send + 'static + Resp: DeserializeOwned + Send + 'static, + E: DeserializeOwned + Send + 'static { let inner = Proto::new(max_payload_size).bind_client(&handle, tcp); Client { inner } @@ -164,8 +165,8 @@ impl Client impl fmt::Debug for Client where Req: Serialize + 'static, - Resp: Deserialize + 'static, - E: Deserialize + 'static + Resp: DeserializeOwned + 'static, + E: DeserializeOwned + 'static { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(f, "Client {{ .. }}") @@ -188,8 +189,8 @@ pub type ConnectFuture = impl ClientExt for Client where Req: Serialize + Send + 'static, - Resp: Deserialize + Send + 'static, - E: Deserialize + Send + 'static + Resp: DeserializeOwned + Send + 'static, + E: DeserializeOwned + Send + 'static { type ConnectFut = ConnectFuture; diff --git a/src/future/server/mod.rs b/src/future/server/mod.rs index 1b7a40b..973c6b6 100644 --- a/src/future/server/mod.rs +++ b/src/future/server/mod.rs @@ -7,7 +7,8 @@ use {bincode, net2}; use errors::WireError; use futures::{Async, Future, Poll, Stream, future as futures}; use protocol::Proto; -use serde::{Deserialize, Serialize}; +use serde::Serialize; +use serde::de::DeserializeOwned; use std::fmt; use std::io; use std::net::SocketAddr; @@ -241,7 +242,7 @@ pub fn listen(new_service: S, where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static { @@ -267,7 +268,7 @@ fn listen_with(new_service: S, where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static { @@ -347,7 +348,7 @@ impl BindStream where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static, I: AsyncRead + AsyncWrite + 'static, @@ -372,7 +373,7 @@ impl Future for BindStream where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static, I: AsyncRead + AsyncWrite + 'static, @@ -399,7 +400,7 @@ pub struct Listen where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static { @@ -410,7 +411,7 @@ impl Future for Listen where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static { @@ -426,7 +427,7 @@ impl fmt::Debug for Listen where S: NewService, Response = Response, Error = io::Error> + 'static, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static { diff --git a/src/macros.rs b/src/macros.rs index 24cd3b4..66eb82f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -56,25 +56,27 @@ macro_rules! impl_serialize { #[macro_export] macro_rules! impl_deserialize { ($impler:ident, $(@($name:ident $n:expr))* -- #($n_:expr) ) => ( - impl $crate::serde::Deserialize for $impler { + impl<'d> $crate::serde::Deserialize<'d> for $impler { #[allow(non_camel_case_types)] fn deserialize( impl_deserialize_deserializer__: impl_deserialize_D__) -> ::std::result::Result<$impler, impl_deserialize_D__::Error> - where impl_deserialize_D__: $crate::serde::Deserializer + where impl_deserialize_D__: $crate::serde::Deserializer<'d> { #[allow(non_camel_case_types, unused)] enum impl_deserialize_Field__ { $($name),* } - impl $crate::serde::Deserialize for impl_deserialize_Field__ { + impl<'d> $crate::serde::Deserialize<'d> for impl_deserialize_Field__ { fn deserialize(impl_deserialize_deserializer__: D) -> ::std::result::Result - where D: $crate::serde::Deserializer + where D: $crate::serde::Deserializer<'d> { struct impl_deserialize_FieldVisitor__; - impl $crate::serde::de::Visitor for impl_deserialize_FieldVisitor__ { + impl<'d> $crate::serde::de::Visitor<'d> + for impl_deserialize_FieldVisitor__ + { type Value = impl_deserialize_Field__; fn expecting(&self, formatter: &mut ::std::fmt::Formatter) @@ -107,13 +109,13 @@ macro_rules! impl_deserialize { ) } } - impl_deserialize_deserializer__.deserialize_struct_field( + impl_deserialize_deserializer__.deserialize_identifier( impl_deserialize_FieldVisitor__) } } struct Visitor; - impl $crate::serde::de::Visitor for Visitor { + impl<'d> $crate::serde::de::Visitor<'d> for Visitor { type Value = $impler; fn expecting(&self, formatter: &mut ::std::fmt::Formatter) @@ -122,16 +124,16 @@ macro_rules! impl_deserialize { formatter.write_str("an enum variant") } - fn visit_enum(self, visitor__: V) + fn visit_enum(self, data__: V) -> ::std::result::Result - where V: $crate::serde::de::EnumVisitor + where V: $crate::serde::de::EnumAccess<'d> { - use $crate::serde::de::VariantVisitor; - match visitor__.visit_variant()? { + use $crate::serde::de::VariantAccess; + match data__.variant()? { $( (impl_deserialize_Field__::$name, variant) => { ::std::result::Result::Ok( - $impler::$name(variant.visit_newtype()?)) + $impler::$name(variant.newtype_variant()?)) } ),* } diff --git a/src/protocol.rs b/src/protocol.rs index be17c3a..b3da9f1 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -53,7 +53,7 @@ fn too_big(payload_size: u64, max_payload_size: u64) -> io::Error { impl Encoder for Codec where Encode: serde::Serialize, - Decode: serde::Deserialize + Decode: serde::de::DeserializeOwned { type Item = (RequestId, Encode); type Error = io::Error; @@ -76,7 +76,7 @@ impl Encoder for Codec } impl Decoder for Codec - where Decode: serde::Deserialize + where Decode: serde::de::DeserializeOwned { type Item = (RequestId, Result); type Error = io::Error; @@ -153,7 +153,7 @@ impl Proto { impl ServerProto for Proto where T: AsyncRead + AsyncWrite + 'static, Encode: serde::Serialize + 'static, - Decode: serde::Deserialize + 'static + Decode: serde::de::DeserializeOwned + 'static { type Response = Encode; type Request = Result; @@ -168,7 +168,7 @@ impl ServerProto for Proto impl ClientProto for Proto where T: AsyncRead + AsyncWrite + 'static, Encode: serde::Serialize + 'static, - Decode: serde::Deserialize + 'static + Decode: serde::de::DeserializeOwned + 'static { type Response = Result; type Request = Encode; diff --git a/src/sync/client.rs b/src/sync/client.rs index bed63eb..6ed3da1 100644 --- a/src/sync/client.rs +++ b/src/sync/client.rs @@ -1,8 +1,8 @@ use future::client::{Client as FutureClient, ClientExt as FutureClientExt, Options as FutureOptions}; -/// Exposes a trait for connecting synchronously to servers. use futures::{Future, Stream}; -use serde::{Deserialize, Serialize}; +use serde::Serialize; +use serde::de::DeserializeOwned; use std::fmt; use std::io; use std::net::{SocketAddr, ToSocketAddrs}; @@ -35,8 +35,8 @@ impl fmt::Debug for Client { impl Client where Req: Serialize + Send + 'static, - Resp: Deserialize + Send + 'static, - E: Deserialize + Send + 'static + Resp: DeserializeOwned + Send + 'static, + E: DeserializeOwned + Send + 'static { /// Drives an RPC call for the given request. pub fn call(&self, request: Req) -> Result> { @@ -124,8 +124,8 @@ pub trait ClientExt: Sized { impl ClientExt for Client where Req: Serialize + Send + 'static, - Resp: Deserialize + Send + 'static, - E: Deserialize + Send + 'static + Resp: DeserializeOwned + Send + 'static, + E: DeserializeOwned + Send + 'static { fn connect(addr: A, options: Options) -> io::Result where A: ToSocketAddrs @@ -154,8 +154,8 @@ struct RequestHandler { impl RequestHandler> where Req: Serialize + Send + 'static, - Resp: Deserialize + Send + 'static, - E: Deserialize + Send + 'static + Resp: DeserializeOwned + Send + 'static, + E: DeserializeOwned + Send + 'static { /// Creates a new `RequestHandler` by connecting a `FutureClient` to the given address /// using the given options. @@ -175,8 +175,8 @@ impl RequestHandler> impl RequestHandler where Req: Serialize + 'static, - Resp: Deserialize + 'static, - E: Deserialize + 'static, + Resp: DeserializeOwned + 'static, + E: DeserializeOwned + 'static, S: Service>, S::Future: 'static { diff --git a/src/sync/server.rs b/src/sync/server.rs index 8cb67fd..fb53ce7 100644 --- a/src/sync/server.rs +++ b/src/sync/server.rs @@ -4,7 +4,8 @@ use futures::{Future, future as futures}; use futures::sync::oneshot; #[cfg(feature = "tls")] use native_tls_inner::TlsAcceptor; -use serde::{Deserialize, Serialize}; +use serde::Serialize; +use serde::de::DeserializeOwned; use std::fmt; use std::io; use std::net::SocketAddr; @@ -110,7 +111,7 @@ pub fn listen(new_service: S, ::Future: Send + 'static, S::Response: Send, S::Error: Send, - Req: Deserialize + 'static, + Req: DeserializeOwned + 'static, Resp: Serialize + 'static, E: Serialize + 'static { diff --git a/src/util.rs b/src/util.rs index 12bc85f..aaded3b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -60,9 +60,9 @@ impl Serialize for Never { } // Please don't try to deserialize this. :( -impl Deserialize for Never { +impl<'a> Deserialize<'a> for Never { fn deserialize(_: D) -> Result - where D: Deserializer + where D: Deserializer<'a> { panic!("Never cannot be instantiated!"); }