feat: provide blanket implementations for ClientHandler and ServerHandler traits (#609)
* feat!: implement ServerHandler for Box<H> and Arc<H> where H is a ServerHandler * feat!: implement ClientHandler for Box<H> and Arc<H> where H is a ClientHandler * test: test Box and Arc have blanket implementations for handler traits * refactor: deduplicate blanket implementations with macros
This commit is contained in:
parent
acb06ea819
commit
81f858836d
1 changed files with 348 additions and 1 deletions
28
crates/rmcp/tests/test_handler_wrappers.rs
Normal file
28
crates/rmcp/tests/test_handler_wrappers.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// cargo test --test test_handler_wrappers --features "client server"
|
||||
|
||||
mod common;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use common::handlers::{TestClientHandler, TestServer};
|
||||
use rmcp::{ClientHandler, ServerHandler};
|
||||
|
||||
#[test]
|
||||
fn test_wrapped_server_handlers() {
|
||||
// This test asserts that, when T: ServerHandler, both Box<T> and Arc<T> also implement ServerHandler.
|
||||
fn accepts_server_handler<H: ServerHandler>(_handler: H) {}
|
||||
|
||||
accepts_server_handler(Box::new(TestServer::new()));
|
||||
accepts_server_handler(Arc::new(TestServer::new()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wrapped_client_handlers() {
|
||||
// This test asserts that, when T: ClientHandler, both Box<T> and Arc<T> also implement ClientHandler.
|
||||
fn accepts_client_handler<H: ClientHandler>(_handler: H) {}
|
||||
|
||||
let client = TestClientHandler::new(false, false);
|
||||
|
||||
accepts_client_handler(Box::new(client.clone()));
|
||||
accepts_client_handler(Arc::new(client));
|
||||
}
|
||||
Loading…
Reference in a new issue