feat: fn that replaces and merges network module's endpoints (#16619)

Signed-off-by: Aliaksei Misiukevich <taberlick@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Aliaksei Misiukevich
2025-06-07 16:51:56 +02:00
committed by GitHub
parent f6dec71dcf
commit 0848739717

View File

@@ -1943,6 +1943,54 @@ impl TransportRpcModules {
self.replace_ipc(other)?;
Ok(true)
}
/// Adds or replaces given [`Methods`] in http module.
///
/// Returns `true` if the methods were replaced or added, `false` otherwise.
pub fn add_or_replace_http(
&mut self,
other: impl Into<Methods>,
) -> Result<bool, RegisterMethodError> {
let other = other.into();
self.remove_http_methods(other.method_names());
self.merge_http(other)
}
/// Adds or replaces given [`Methods`] in ws module.
///
/// Returns `true` if the methods were replaced or added, `false` otherwise.
pub fn add_or_replace_ws(
&mut self,
other: impl Into<Methods>,
) -> Result<bool, RegisterMethodError> {
let other = other.into();
self.remove_ws_methods(other.method_names());
self.merge_ws(other)
}
/// Adds or replaces given [`Methods`] in ipc module.
///
/// Returns `true` if the methods were replaced or added, `false` otherwise.
pub fn add_or_replace_ipc(
&mut self,
other: impl Into<Methods>,
) -> Result<bool, RegisterMethodError> {
let other = other.into();
self.remove_ipc_methods(other.method_names());
self.merge_ipc(other)
}
/// Adds or replaces given [`Methods`] in all configured network modules.
pub fn add_or_replace_configured(
&mut self,
other: impl Into<Methods>,
) -> Result<(), RegisterMethodError> {
let other = other.into();
self.add_or_replace_http(other.clone())?;
self.add_or_replace_ws(other.clone())?;
self.add_or_replace_ipc(other)?;
Ok(())
}
}
/// Returns the methods installed in the given module that match the given filter.