feat: add merge_if_module_configured (#12608)

This commit is contained in:
Matthias Seitz
2024-11-18 10:17:55 +01:00
committed by GitHub
parent 7ae8ce1d00
commit cfd4523537

View File

@ -1999,6 +1999,29 @@ impl TransportRpcModules {
&self.config &self.config
} }
/// Merge the given [`Methods`] in all configured transport modules if the given
/// [`RethRpcModule`] is configured for the transport.
///
/// Fails if any of the methods in other is present already.
pub fn merge_if_module_configured(
&mut self,
module: RethRpcModule,
other: impl Into<Methods>,
) -> Result<(), RegisterMethodError> {
let other = other.into();
if self.module_config().contains_http(&module) {
self.merge_http(other.clone())?;
}
if self.module_config().contains_ws(&module) {
self.merge_ws(other.clone())?;
}
if self.module_config().contains_ipc(&module) {
self.merge_ipc(other)?;
}
Ok(())
}
/// Merge the given [Methods] in the configured http methods. /// Merge the given [Methods] in the configured http methods.
/// ///
/// Fails if any of the methods in other is present already. /// Fails if any of the methods in other is present already.