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:
parent
7a67482777
commit
663d5a75f3
1 changed files with 8 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue