From 663d5a75f348229dffbbeb130efb788d1684f6bd Mon Sep 17 00:00:00 2001 From: John Howard Date: Fri, 29 Aug 2025 03:17:59 -0700 Subject: [PATCH] feat(model): add helpers to build enum from concrete values (#393) 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 358a3b1..73d622c 100644 --- a/crates/rmcp/src/model.rs +++ b/crates/rmcp/src/model.rs @@ -1474,6 +1474,14 @@ macro_rules! ts_union { pub enum $U { $($V($V),)* } + + $( + impl From<$V> for $U { + fn from(value: $V) -> Self { + $U::$V(value) + } + } + )* }; } @@ -1598,17 +1606,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