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);
```
This commit is contained in:
John Howard 2025-08-29 03:17:59 -07:00 • committed by GitHub
commit 663d5a75f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<CancelledNotification> for ClientNotification {
}
}
}
impl From<CancelledNotification> for ServerNotification {
fn from(value: CancelledNotification) -> Self {
ServerNotification::CancelledNotification(value)
}
}
impl From<CancelledNotification> for ClientNotification {
fn from(value: CancelledNotification) -> Self {
ClientNotification::CancelledNotification(value)
}
}
// =============================================================================
// TESTS