Skip to content

Associated types in RPC traits #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 23 additions & 2 deletions macros/src/auto_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use jsonrpc_core::futures::{self, Future, IntoFuture};
use jsonrpc_core::futures::future::{self, Either};
use jsonrpc_pubsub::{PubSubMetadata, Subscriber};
use pubsub;
use serde::Serialize;
pub use serde::Serialize;
use serde::de::DeserializeOwned;
use util::{invalid_params, expect_no_params, to_value};

Expand Down Expand Up @@ -76,6 +76,12 @@ macro_rules! build_rpc_trait {
(
$(#[$t_attr: meta])*
pub trait $name: ident {
$(
ASSOCIATED
$( #[doc=$t_doc:expr] )*
type $t_name:ident;
)*

$(
$( #[doc=$m_doc:expr] )*
#[ rpc( $($t:tt)* ) ]
Expand All @@ -85,6 +91,11 @@ macro_rules! build_rpc_trait {
) => {
$(#[$t_attr])*
pub trait $name: Sized + Send + Sync + 'static {
$(
$(#[doc=$t_doc])*
type $t_name: Send + $crate::Serialize;
)*

$(
$(#[doc=$m_doc])*
fn $m_name ( $($p)* ) -> $result<$out $(, $error)* > ;
Expand All @@ -111,6 +122,12 @@ macro_rules! build_rpc_trait {
pub trait $name: ident {
type Metadata;

$(
ASSOCIATED
$( #[doc=$t_doc:expr] )*
type $t_name:ident;
)*

$(
$( #[ doc=$m_doc:expr ] )*
#[ rpc( $($t:tt)* ) ]
Expand All @@ -137,6 +154,11 @@ macro_rules! build_rpc_trait {
$( $sub_name )*
);

$(
$(#[doc=$t_doc])*
type $t_name: Send + $crate::Serialize;
)*

$(
$(#[doc=$m_doc])*
fn $m_name ( $($p)* ) -> $result <$out $(, $error_std) *>;
Expand Down Expand Up @@ -630,4 +652,3 @@ wrap_with_trailing!(4, A, B, C, D);
wrap_with_trailing!(3, A, B, C);
wrap_with_trailing!(2, A, B);
wrap_with_trailing!(1, A);

2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod util;
pub mod pubsub;

#[doc(hidden)]
pub use auto_args::{WrapAsync, WrapMeta, WrapSubscribe};
pub use auto_args::{WrapAsync, WrapMeta, WrapSubscribe, Serialize};
pub use auto_args::Trailing;
pub use delegates::IoDelegate;
pub use util::to_value;