Skip to content

Commit e1fcca9

Browse files
committed
feat(model): add helpers to build enum from concrete values
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 a84a3eb commit e1fcca9

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

crates/rmcp/src/model.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,14 @@ macro_rules! ts_union {
14711471
pub enum $U {
14721472
$($V($V),)*
14731473
}
1474+
1475+
$(
1476+
impl From<$V> for $U {
1477+
fn from(value: $V) -> Self {
1478+
$U::$V(value)
1479+
}
1480+
}
1481+
)*
14741482
};
14751483
}
14761484

@@ -1575,17 +1583,6 @@ impl TryInto<CancelledNotification> for ClientNotification {
15751583
}
15761584
}
15771585
}
1578-
impl From<CancelledNotification> for ServerNotification {
1579-
fn from(value: CancelledNotification) -> Self {
1580-
ServerNotification::CancelledNotification(value)
1581-
}
1582-
}
1583-
1584-
impl From<CancelledNotification> for ClientNotification {
1585-
fn from(value: CancelledNotification) -> Self {
1586-
ClientNotification::CancelledNotification(value)
1587-
}
1588-
}
15891586

15901587
// =============================================================================
15911588
// TESTS

0 commit comments

Comments
 (0)