From e1fcca988a4d2ad6be09f618e11acf5f205c6468 Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 27 Aug 2025 09:08:24 -0700 Subject: [PATCH] feat(model): add helpers to build enum from concrete values This allows building functions like ```rust fn stream(resp: impl Into, req_id: RequestId) -> Result { let rpc = ServerJsonRpcMessage::response(resp.into(), req_id); ``` --- crates/rmcp/src/model.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/rmcp/src/model.rs b/crates/rmcp/src/model.rs index d2cd43db..ba2c2a61 100644 --- a/crates/rmcp/src/model.rs +++ b/crates/rmcp/src/model.rs @@ -1471,6 +1471,14 @@ macro_rules! ts_union { pub enum $U { $($V($V),)* } + + $( + impl From<$V> for $U { + fn from(value: $V) -> Self { + $U::$V(value) + } + } + )* }; } @@ -1575,17 +1583,6 @@ impl TryInto for ClientNotification { } } } -impl From for ServerNotification { - fn from(value: CancelledNotification) -> Self { - ServerNotification::CancelledNotification(value) - } -} - -impl From for ClientNotification { - fn from(value: CancelledNotification) -> Self { - ClientNotification::CancelledNotification(value) - } -} // ============================================================================= // TESTS