-
Notifications
You must be signed in to change notification settings - Fork 154
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
Macros error #1221
Comments
You could just do: #[cfg_attr(feature = "server", rpc(client, server))]
#[cfg_attr(not(feature = "server"), rpc(client))]
pub trait BrainRpc {
#[method(name = "getStatus")]
async fn get_status(&self) -> Result<(), ErrorObjectOwned>;
} I think the |
Smaller reproducation of this macro_rules! rpc_trait {
($visibility:vis trait $name:ident {$($body:tt)*}) =>
{
mod trait_definition {
use super::*;
#[rpc(client)]
$visibility trait $name {
$($body)*
}
}
pub use trait_definition::*;
};
}
rpc_trait! {
pub trait BrainRpc {
#[method(name = "getStatus")]
async fn get_status(&self) -> Result<(), ErrorObjectOwned>;
}
} This expands to mod trait_definition {
use super::*;
///Client implementation for the `BrainRpc` RPC API.
pub trait BrainRpcClient: jsonrpsee::core::client::ClientT {
#[allow(non_snake_case)]
#[allow(clippy::used_underscore_binding)]
#[must_use]
#[allow(
clippy::async_yields_async,
clippy::diverging_sub_expression,
clippy::let_unit_value,
clippy::no_effect_underscore_binding,
clippy::shadow_same,
clippy::type_complexity,
clippy::type_repetition_in_bounds,
clippy::used_underscore_binding
)]
fn get_status<'life0, 'async_trait>(
&'life0 self,
) -> ::core::pin::Pin<
Box<
dyn ::core::future::Future<
Output = Result<(), jsonrpsee::core::client::Error>,
> + ::core::marker::Send + 'async_trait,
>,
>
where
'life0: 'async_trait,
Self: ::core::marker::Sync + 'async_trait,
{
Box::pin(async move {
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<
Result<(), jsonrpsee::core::client::Error>,
> {
#[allow(unreachable_code)] return __ret;
}
let __self = self;
let __ret: Result<(), jsonrpsee::core::client::Error> = {
let params = { { jsonrpsee::core::params::ArrayParams::new() } };
__self.request("getStatus", params).await
};
#[allow(unreachable_code)] __ret
})
}
}
impl<TypeJsonRpseeInteral> BrainRpcClient for TypeJsonRpseeInteral
where
TypeJsonRpseeInteral: jsonrpsee::core::client::ClientT,
{}
}
pub use trait_definition::*; The generated code works by itself so I don't really follow why it doesn't work but with that said it it isn't an |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I've started to use jsonrpsee recently. I've created a common cargo crate in my workspace with my Rpc traits and this crate is used in a leptos wasm app and in a tokio backend.
I've tried to write a macro_rules! to conditionally include the RpcServer in the decorator macro as follow:
but I have the following error:
Does someone have any idea of a way to fix it ?
The text was updated successfully, but these errors were encountered: