Can't use params
as parameter name when using subscription
proc-macro attribute #1362
Closed
Description
Rust toolchain
stable-aarch64-apple-darwin (default)
rustc 1.77.2 (25ef9e3d8 2024-04-09)
Example:
[package]
name = "rpc-demo"
version = "0.1.0"
edition = "2021"
[dependencies]
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "master", features = ["client-core", "server-core", "macros"] }
serde = { version = "1.0", features = ["derive"] }
use jsonrpsee::{core::SubscriptionResult, proc_macros::rpc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub enum PubSubKind {
A,
B,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PubSubParams {
params: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PubSubItem {
result: String,
}
#[rpc(client, server, namespace = "foo")]
#[async_trait]
pub trait FooPubSubApi {
// Error
// #[subscription(name = "subscribe" => "subscription", unsubscribe = "unsubscribe", item = PubSubItem)]
// async fn sub(&self, kind: PubSubKind, params: Option<PubSubParams>) -> SubscriptionResult;
// OK
#[subscription(name = "subscribe" => "subscription", unsubscribe = "unsubscribe", item = PubSubItem)]
async fn sub(&self, kind: PubSubKind, pubsub_params: Option<PubSubParams>) -> SubscriptionResult;
}
Error:
error[E0277]: the trait bound `ArrayParams: Serialize` is not satisfied
--> src/lib.rs:24:40
|
20 | #[rpc(client, server, namespace = "foo")]
| ----------------------------------------- required by a bound introduced by this call
...
24 | async fn sub(&self, kind: PubSubKind, params: Option<PubSubParams>) -> Subscript...
| ^^^^^^ the trait `Serialize` is not implemented for `ArrayParams`
|
= help: the following other types implement trait `Serialize`:
bool
char
isize
i8
i16
i32
i64
i128
and 148 others
note: required by a bound in `ArrayParams::insert`
--> /Users/qinxuan/.cargo/git/checkouts/jsonrpsee-5ae67701a3cedc92/c908eeb/core/src/params.rs:200:19
|
200 | pub fn insert<P: Serialize>(&mut self, value: P) -> Result<(), serde_json::Error> {
| ^^^^^^^^^ required by this bound in `ArrayParams::insert`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rpc-demo` (lib) due to 1 previous error
Metadata
Assignees
Labels
No labels