You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use jsonrpsee::{async_client::Client, proc_macros::rpc};pubtraitSuper{}#[rpc(client, server)]traitRpc:Super{#[method(name = "method")]fnmethod(&self){}}fntakes_super<T:Super>(){}fnmain(){takes_super::<Client>()}
Results in the following error:
error[E0277]: the trait bound `Client: Super` is not satisfied
--> src/main.rs:14:19
|
14 | takes_super::<Client>()
| ^^^^^^ the trait `Super` is not implemented for `Client`
|
Although this makes sense (Client does not impl Super), this behaviour is very confusing since the Super bound on Rpc is not rejected. I also attempted to use the client_bounds and server_bounds attributes, which does indeed require Super to be implemented:
error[E0277]: the trait bound `Client: Super` is not satisfied
--> src/main.rs:21:19
|
21 | takes_super::<Client>();
| ^^^^^^ the trait `Super` is not implemented for `Client`
|
error[E0277]: the trait bound `Client: RpcClient` is not satisfied
--> src/main.rs:22:24
|
22 | takes_rpc_client::<Client>();
| ^^^^^^ the trait `Super` is not implemented for `Client`, which is required by `Client: RpcClient`
|
However, any attempt to use Super in the #[rpc] definition causes issues:
error[E0277]: the trait bound `Self: Super` is not satisfied
--> src/main.rs:19:29
|
19 | fn method(&self, assoc: <Self as Super>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Super` is not implemented for `Self`
|
help: consider further restricting `Self`
|
19 | fn method(&self, assoc: <Self as Super>::Assoc) where Self: Super {}
| +++++++++++++++++
error[E0277]: the trait bound `Self: Super` is not satisfied
--> src/main.rs:19:53
|
19 | fn method(&self, assoc: <Self as Super>::Assoc) {}
| ^^ the trait `Super` is not implemented for `Self`
|
help: consider further restricting `Self`
|
19 | fn method(&self, assoc: <Self as Super>::Assoc) where Self: Super {}
| +++++++++++++++++
error[E0277]: the trait bound `Client: Super` is not satisfied
--> src/main.rs:27:19
|
27 | takes_super::<Client>();
| ^^^^^^ the trait `Super` is not implemented for `Client`
|
note: required by a bound in `takes_super`
--> src/main.rs:22:19
|
22 | fn takes_super<T: Super>() {}
| ^^^^^ required by this bound in `takes_super`
error[E0277]: the trait bound `Client: RpcClient` is not satisfied
--> src/main.rs:28:24
|
28 | takes_rpc_client::<Client>();
| ^^^^^^ the trait `Super` is not implemented for `Client`, which is required by `Client: RpcClient`
|
note: required for `Client` to implement `RpcClient`
--> src/main.rs:11:1
|
11 | / #[rpc(
12 | | client,
13 | | server,
14 | | client_bounds(Self: Super),
15 | | server_bounds(Self: Super)
16 | | )]
| |__^
17 | trait Rpc: Super {
| ^^^
note: required by a bound in `takes_rpc_client`
--> src/main.rs:24:24
|
24 | fn takes_rpc_client<T: RpcClient>() {}
| ^^^^^^^^^ required by this bound in `takes_rpc_client`
= note: this error originates in the attribute macro `rpc` (in Nightly builds, run with -Z macro-backtrace for more info)
While I'm not sure what the best behaviour is here, I think it would probably be best to reject super traits on the trait definition entirely (since they're just outright ignored currently), and clarify in the documentation that the server_bounds only applies to the generated into_rpc method, not the entire *Server trait (whereas it applies to the entire *Client trait):
///Server trait implementation for the `Rpc` RPC API.pubtraitRpcServer:Sized + Send + Sync + 'static {// < no `Super` or `ServerBound` boundfnmethod(&self,assoc: <SelfasSuper>::Assoc){}///Collects all the methods and subscriptions defined in the trait and adds them into a single `RpcModule`.fninto_rpc(self) -> jsonrpsee::RpcModule<Self>whereSelf:ServerBound,// < `ServerBound` bound is only on the `into_rpc` method{// snip}}///Client implementation for the `Rpc` RPC API.pubtraitRpcClient: jsonrpsee::core::client::ClientTwhereSelf:ClientBound,{fnmethod<'life0,'async_trait>(&'life0 self,assoc: <SelfasSuper>::Assoc,) -> ::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,{// snip}}impl<TypeJsonRpseeInteral>RpcClientforTypeJsonRpseeInteralwhereTypeJsonRpseeInteral: jsonrpsee::core::client::ClientT,Self:ClientBound,{}
The text was updated successfully, but these errors were encountered:
The following code:
Results in the following error:
Although this makes sense (
Client
does not implSuper
), this behaviour is very confusing since theSuper
bound onRpc
is not rejected. I also attempted to use theclient_bounds
andserver_bounds
attributes, which does indeed requireSuper
to be implemented:However, any attempt to use
Super
in the#[rpc]
definition causes issues:While I'm not sure what the best behaviour is here, I think it would probably be best to reject super traits on the trait definition entirely (since they're just outright ignored currently), and clarify in the documentation that the
server_bounds
only applies to the generatedinto_rpc
method, not the entire*Server
trait (whereas it applies to the entire*Client
trait):The text was updated successfully, but these errors were encountered: