Skip to content

Commit cc8f26d

Browse files
simeir4tomusdrw
authored andcommitted
Solve compiler error when serde is not a dependency of user project (#481) (#498)
Use `serde` directly instead of ask for user of the library to add it as a dependency. Tests are modified since this is a ui change. The doc comment gives an example using `#[rpc(server)]` instead of original `#[rpc]`, telling users that this attribute has an option to be used to configure it.
1 parent 7b94363 commit cc8f26d

19 files changed

Lines changed: 48 additions & 57 deletions

core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub use futures;
3030

3131
#[doc(hidden)]
3232
pub extern crate serde_json;
33+
#[doc(hidden)]
34+
pub extern crate serde;
3335

3436
mod calls;
3537
mod io;

derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! use jsonrpc_core::{IoHandler, Error, Result};
1010
//! use jsonrpc_core::futures::future::{self, FutureResult};
1111
//!
12-
//! #[rpc]
12+
//! #[rpc(server)]
1313
//! pub trait Rpc {
1414
//! #[rpc(name = "protocolVersion")]
1515
//! fn protocol_version(&self) -> Result<String>;

derive/src/rpc_trait.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ pub fn rpc_impl(input: syn::Item, options: DeriveOptions) -> Result<proc_macro2:
236236
let mod_name_ident = rpc_wrapper_mod_name(&rpc_trait);
237237

238238
let core_name = crate_name("jsonrpc-core")?;
239-
let serde_name = crate_name("serde")?;
240239

241240
let mut submodules = Vec::new();
242241
let mut exports = Vec::new();
@@ -256,7 +255,6 @@ pub fn rpc_impl(input: syn::Item, options: DeriveOptions) -> Result<proc_macro2:
256255
}
257256
Ok(quote!(
258257
mod #mod_name_ident {
259-
use #serde_name as _serde;
260258
use #core_name as _jsonrpc_core;
261259
use super::*;
262260

derive/src/to_delegate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,17 @@ pub fn generate_where_clause_serialization_predicates(
449449
// add json serialization trait bounds
450450
if client {
451451
if visitor.server_to_client_type_params.contains(&ty.ident) {
452-
bounds.push(parse_quote!(_serde::de::DeserializeOwned))
452+
bounds.push(parse_quote!(_jsonrpc_core::serde::de::DeserializeOwned))
453453
}
454454
if visitor.client_to_server_type_params.contains(&ty.ident) {
455-
bounds.push(parse_quote!(_serde::Serialize))
455+
bounds.push(parse_quote!(_jsonrpc_core::serde::Serialize))
456456
}
457457
} else {
458458
if visitor.server_to_client_type_params.contains(&ty.ident) {
459-
bounds.push(parse_quote!(_serde::Serialize))
459+
bounds.push(parse_quote!(_jsonrpc_core::serde::Serialize))
460460
}
461461
if visitor.client_to_server_type_params.contains(&ty.ident) {
462-
bounds.push(parse_quote!(_serde::de::DeserializeOwned))
462+
bounds.push(parse_quote!(_jsonrpc_core::serde::de::DeserializeOwned))
463463
}
464464
}
465465
syn::WherePredicate::Type(syn::PredicateType {

derive/tests/run-pass/client_only.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate serde;
21
extern crate jsonrpc_core;
32
extern crate jsonrpc_core_client;
43
#[macro_use]

derive/tests/run-pass/pubsub-dependency-not-required-for-vanilla-rpc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate serde;
21
extern crate jsonrpc_core;
32
extern crate jsonrpc_core_client;
43
#[macro_use]

derive/tests/run-pass/server_only.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate serde;
21
extern crate jsonrpc_core;
32
#[macro_use]
43
extern crate jsonrpc_derive;

derive/tests/ui/attr-invalid-meta-list-names.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate serde;
21
extern crate jsonrpc_core;
32
#[macro_use]
43
extern crate jsonrpc_derive;
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Invalid attribute parameter(s): 'Xalias'. Expected 'alias'
2-
--> $DIR/attr-invalid-meta-list-names.rs:8:2
3-
|
4-
8 | /// Returns a protocol version
5-
| _____^
6-
9 | | #[rpc(name = "protocolVersion", Xalias("alias"))]
7-
10 | | fn protocol_version(&self) -> Result<String>;
8-
| |_________________________________________________^
2+
--> $DIR/attr-invalid-meta-list-names.rs:7:2
3+
|
4+
7 | /// Returns a protocol version
5+
| _____^
6+
8 | | #[rpc(name = "protocolVersion", Xalias("alias"))]
7+
9 | | fn protocol_version(&self) -> Result<String>;
8+
| |_________________________________________________^

derive/tests/ui/attr-invalid-meta-words.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate serde;
21
extern crate jsonrpc_core;
32
#[macro_use]
43
extern crate jsonrpc_derive;

0 commit comments

Comments
 (0)