Skip to content

Commit

Permalink
feat: add Methods::merge_replace
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Mar 28, 2023
1 parent 945e086 commit 1250656
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This release adds `Clone` and `Copy` implementations.

### [Added]

- add `Methods::merge_replace` ([#951](https://github.com/paritytech/jsonrpsee/pull/951))
- add missing `Clone` and `Copy` impls ([#951](https://github.com/paritytech/jsonrpsee/pull/951))
- TowerService should be clone-able for handling concurrent request ([#950](https://github.com/paritytech/jsonrpsee/pull/950))

Expand Down
12 changes: 12 additions & 0 deletions core/src/server/rpc_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ impl Methods {
Ok(())
}

/// Merge two [`Methods`]'s by adding all [`MethodCallback`]s from `other` into `self`.
///
/// Unlike [Self::merge], existing callbacks are replaced.
pub fn merge_replace(&mut self, other: impl Into<Methods>) {
let mut other = other.into();

let callbacks = self.mut_callbacks();
for (name, callback) in other.mut_callbacks().drain() {
callbacks.insert(name, callback);
}
}

/// Returns the method callback.
pub fn method(&self, method_name: &str) -> Option<&MethodCallback> {
self.callbacks.get(method_name)
Expand Down

0 comments on commit 1250656

Please sign in to comment.