-
Notifications
You must be signed in to change notification settings - Fork 172
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
Support overriding existing Methods Callbacks #1053
Comments
Hey @mattsse The methods are really "static" i.e, after the server has been started then it's not possible change or override the methods. I think |
right, I'm talking about the setup phase. for example, you have a bunch of #[rpc(server))]
pub trait MyApi {
async fn do_stuff() {}
}
#[rpc(server))]
pub trait MyApi2 {
async fn do_other_stuff() {}
}
fn default_setup () -> RpcModule {
let mut module = RpcModule::new(());
module.merge(MyApi::new().into_rpc()).unwrap();
module.merge(MyApi2::new().into_rpc()).unwrap();
module
} now RpcModule is a list of methods. it would be useful to now replace certain methods with something like #[rpc(server))]
pub trait Unsupported {
async fn do_stuff() {
return Err("Unsupported method: do_stuff")
}
}
fn customize(m: Unsupported) -> RpcModule {
default_setup().merge_replace(m.into_rpc())
} So the motivation behind this is to make it easier to selectively replace certain methods in the default config.
cool, I can try adding these |
sounds good 👍 |
Currently, it's not possible to override
MethodCallback
inMethods
becauseMethods::merge
fails early if a callback with the name already existsjsonrpsee/core/src/server/rpc_module.rs
Lines 355 to 357 in a0ce8d4
This makes it impossible to disable various callbacks dynamically when
RpcModule
s (via server proc macro'sinto_rpc
) are merged.now that
verify_method_name
is public this could be solved by:Methods::iter
andMethods::into_iter
so callbacks can be inserted individually.Methods::merge_replace
which replaces existing handlersThe text was updated successfully, but these errors were encountered: