fix: gate client handler bounds for local (#1068)
This commit is contained in:
parent
fff05d40fd
commit
e5403cf956
3 changed files with 210 additions and 176 deletions
|
|
@ -238,6 +238,11 @@ required-features = [
|
|||
]
|
||||
path = "tests/test_with_js.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_local_client_handler"
|
||||
required-features = ["client", "local"]
|
||||
path = "tests/test_local_client_handler.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_notification"
|
||||
required-features = ["server", "client"]
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ impl<H: ClientHandler> Service<RoleClient> for H {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub trait ClientHandler: Sized + Send + Sync + 'static {
|
||||
macro_rules! client_handler_methods {
|
||||
() => {
|
||||
fn ping(
|
||||
&self,
|
||||
context: RequestContext<RoleClient>,
|
||||
|
|
@ -268,6 +268,19 @@ pub trait ClientHandler: Sized + Send + Sync + 'static {
|
|||
fn get_info(&self) -> ClientInfo {
|
||||
ClientInfo::default()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[cfg(not(feature = "local"))]
|
||||
pub trait ClientHandler: Sized + Send + Sync + 'static {
|
||||
client_handler_methods!();
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[cfg(feature = "local")]
|
||||
pub trait ClientHandler: Sized + 'static {
|
||||
client_handler_methods!();
|
||||
}
|
||||
|
||||
/// Do nothing, with default client info.
|
||||
|
|
|
|||
16
crates/rmcp/tests/test_local_client_handler.rs
Normal file
16
crates/rmcp/tests/test_local_client_handler.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use rmcp::ClientHandler;
|
||||
|
||||
struct LocalClientHandler {
|
||||
_state: Rc<()>,
|
||||
}
|
||||
|
||||
impl ClientHandler for LocalClientHandler {}
|
||||
|
||||
#[test]
|
||||
fn client_handler_accepts_non_send_sync_state_with_local_feature() {
|
||||
fn assert_client_handler<T: ClientHandler>() {}
|
||||
|
||||
assert_client_handler::<LocalClientHandler>();
|
||||
}
|
||||
Loading…
Reference in a new issue