Skip to content

Commit 663d5a7

Browse files
authored
feat(model): add helpers to build enum from concrete values (#393)
This allows building functions like ```rust fn stream(resp: impl Into<ServerResult>, req_id: RequestId) -> Result<Response, UpstreamError> { let rpc = ServerJsonRpcMessage::response(resp.into(), req_id); ```
1 parent 7a67482 commit 663d5a7

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

crates/rmcp/src/model.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,14 @@ macro_rules! ts_union {
14741474
pub enum $U {
14751475
$($V($V),)*
14761476
}
1477+
1478+
$(
1479+
impl From<$V> for $U {
1480+
fn from(value: $V) -> Self {
1481+
$U::$V(value)
1482+
}
1483+
}
1484+
)*
14771485
};
14781486
}
14791487

@@ -1598,17 +1606,6 @@ impl TryInto<CancelledNotification> for ClientNotification {
15981606
}
15991607
}
16001608
}
1601-
impl From<CancelledNotification> for ServerNotification {
1602-
fn from(value: CancelledNotification) -> Self {
1603-
ServerNotification::CancelledNotification(value)
1604-
}
1605-
}
1606-
1607-
impl From<CancelledNotification> for ClientNotification {
1608-
fn from(value: CancelledNotification) -> Self {
1609-
ClientNotification::CancelledNotification(value)
1610-
}
1611-
}
16121609

16131610
// =============================================================================
16141611
// TESTS

0 commit comments

Comments
 (0)