Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"test-utils",
"tests",
"tests/wasm-tests",
"tests/proc-macro-core",
"types",
]
resolver = "2"
Expand Down
4 changes: 4 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub mod __reexports {
pub use async_trait::async_trait;
pub use serde;
pub use serde_json;

cfg_client_or_server! {
pub use tokio;
}
}

pub use beef::Cow;
Expand Down
9 changes: 9 additions & 0 deletions core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ macro_rules! cfg_server {
};
}

macro_rules! cfg_client_or_server {
($($item:item)*) => {
$(
#[cfg(any(feature = "client", feature = "server"))]
$item
)*
}
}

macro_rules! cfg_http_helpers {
($($item:item)*) => {
cfg_feature!("http-helpers", $($item)*);
Expand Down
2 changes: 1 addition & 1 deletion proc-macros/src/render_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl RpcDescription {
let tracing = self.jrps_server_item(quote! { tracing });
let sub_err = self.jrps_server_item(quote! { SubscriptionCloseResponse });
let response_payload = self.jrps_server_item(quote! { ResponsePayload });
let tokio = self.jrps_server_item(quote! { tokio });
let tokio = self.jrps_server_item(quote! { core::__reexports::tokio });

// Code to decode sequence of parameters from a JSON array.
let decode_array = {
Expand Down
11 changes: 11 additions & 0 deletions tests/proc-macro-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "jsonrpsee-proc-macro-core"
description = "Test crate to make sure that jsonrpsee core compiles"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
publish = false

[dependencies]
jsonrpsee = { path = "../../jsonrpsee", features = ["server-core", "client-core", "macros"] }
56 changes: 56 additions & 0 deletions tests/proc-macro-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Test module for the proc-macro API to make sure that is compiles with core features.

use jsonrpsee::core::{async_trait, SubscriptionResult};
use jsonrpsee::proc_macros::rpc;
use jsonrpsee::types::ErrorObjectOwned;
use jsonrpsee::{ConnectionDetails, PendingSubscriptionSink, SubscriptionMessage};

#[rpc(client, server)]
pub trait Api {
#[method(name = "sync_call")]
fn sync_call(&self, _x: String) -> Result<String, ErrorObjectOwned>;

#[method(name = "async_call")]
async fn async_call(&self, _x: String) -> Result<String, ErrorObjectOwned>;

#[subscription(name = "subscribe", item = String)]
async fn sub(&self, _x: String) -> SubscriptionResult;

#[subscription(name = "subscribeSync", item = String)]
fn sync_sub(&self, _x: String) -> SubscriptionResult;

#[method(name = "blocking", blocking)]
fn blocking_method(&self, _x: String) -> Result<u16, ErrorObjectOwned>;

#[method(name = "raw", raw_method)]
async fn raw(&self, _x: String) -> Result<u16, ErrorObjectOwned>;
}

#[async_trait]
impl ApiServer for () {
fn sync_call(&self, _x: String) -> Result<String, ErrorObjectOwned> {
Ok("sync_call".to_string())
}

async fn async_call(&self, _x: String) -> Result<String, ErrorObjectOwned> {
Ok("async_call".to_string())
}

async fn sub(&self, pending: PendingSubscriptionSink, _x: String) -> SubscriptionResult {
let sink = pending.accept().await?;
sink.send(SubscriptionMessage::from("msg")).await?;
Ok(())
}

fn sync_sub(&self, _sink: PendingSubscriptionSink, _x: String) -> SubscriptionResult {
Ok(())
}

fn blocking_method(&self, _x: String) -> Result<u16, ErrorObjectOwned> {
Ok(42)
}

async fn raw(&self, _conn: ConnectionDetails, _x: String) -> Result<u16, ErrorObjectOwned> {
Ok(42)
}
}