diff --git a/plugins/src/lib.rs b/plugins/src/lib.rs index ae555ad..df5a910 100644 --- a/plugins/src/lib.rs +++ b/plugins/src/lib.rs @@ -240,7 +240,10 @@ pub fn service(attr: TokenStream, input: TokenStream) -> TokenStream { let args: &[&[PatType]] = &rpcs.iter().map(|rpc| &*rpc.args).collect::>(); let response_fut_name = &format!("{}ResponseFut", ident.unraw()); let derive_serialize = if derive_serde.0 { - Some(quote!(#[derive(serde::Serialize, serde::Deserialize)])) + Some( + quote! {#[derive(tarpc::serde::Serialize, tarpc::serde::Deserialize)] + #[serde(crate = "tarpc::serde")]}, + ) } else { None }; diff --git a/tarpc/src/lib.rs b/tarpc/src/lib.rs index af0448c..4a24b06 100644 --- a/tarpc/src/lib.rs +++ b/tarpc/src/lib.rs @@ -3,7 +3,6 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. - //! *Disclaimer*: This is not an official Google product. //! //! tarpc is an RPC framework for rust with a focus on ease of use. Defining a @@ -204,6 +203,9 @@ pub mod rpc; pub use rpc::*; +#[cfg(feature = "serde1")] +pub use serde; + #[cfg(feature = "serde-transport")] #[cfg_attr(docsrs, doc(cfg(feature = "serde-transport")))] pub mod serde_transport; diff --git a/tarpc/src/rpc.rs b/tarpc/src/rpc.rs index b48b7a5..940cbe3 100644 --- a/tarpc/src/rpc.rs +++ b/tarpc/src/rpc.rs @@ -55,7 +55,7 @@ pub enum ClientMessage { Cancel { /// The trace context associates the message with a specific chain of causally-related actions, /// possibly orchestrated across many distributed systems. - #[cfg_attr(feature = "serde", serde(default))] + #[cfg_attr(feature = "serde1", serde(default))] trace_context: trace::Context, /// The ID of the request to cancel. request_id: u64, diff --git a/tarpc/src/rpc/util.rs b/tarpc/src/rpc/util.rs index de4699a..0ec48fc 100644 --- a/tarpc/src/rpc/util.rs +++ b/tarpc/src/rpc/util.rs @@ -10,8 +10,8 @@ use std::{ time::{Duration, SystemTime}, }; -#[cfg(feature = "serde")] -#[cfg_attr(docsrs, doc(cfg(feature = "serde")))] +#[cfg(feature = "serde1")] +#[cfg_attr(docsrs, doc(cfg(feature = "serde1")))] pub mod serde; /// Extension trait for [SystemTimes](SystemTime) in the future, i.e. deadlines. diff --git a/tarpc/src/trace.rs b/tarpc/src/trace.rs index 28ac418..b3f03da 100644 --- a/tarpc/src/trace.rs +++ b/tarpc/src/trace.rs @@ -27,7 +27,7 @@ use std::{ /// Consists of a span identifying an event, an optional parent span identifying a causal event /// that triggered the current span, and a trace with which all related spans are associated. #[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub struct Context { /// An identifier of the trace associated with the current context. A trace ID is typically /// created at a root span and passed along through all causal events. @@ -47,12 +47,12 @@ pub struct Context { /// A 128-bit UUID identifying a trace. All spans caused by the same originating span share the /// same trace ID. #[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub struct TraceId(u128); /// A 64-bit identifier of a span within a trace. The identifier is unique within the span's trace. #[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub struct SpanId(u64); impl Context { diff --git a/tarpc/tests/compile_fail/tarpc_server_missing_async.stderr b/tarpc/tests/compile_fail/tarpc_server_missing_async.stderr index d133dfb..318e420 100644 --- a/tarpc/tests/compile_fail/tarpc_server_missing_async.stderr +++ b/tarpc/tests/compile_fail/tarpc_server_missing_async.stderr @@ -9,11 +9,3 @@ error: hint: `#[tarpc::server]` only rewrites async fns, and `fn hello` is not a | 10 | fn hello(name: String) -> String { | ^^ - -error[E0433]: failed to resolve: use of undeclared type or module `serde` - --> $DIR/tarpc_server_missing_async.rs:1:1 - | -1 | #[tarpc::service] - | ^^^^^^^^^^^^^^^^^ use of undeclared type or module `serde` - | - = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)