-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.rs
42 lines (34 loc) · 1009 Bytes
/
message.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Message type definitions for REST process
use caryatid_sdk::messages::{RESTRequest, RESTResponse, GetRESTResponse};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum Message {
None(()), // Just so we have a simple default
RESTRequest(RESTRequest), // REST request
RESTResponse(RESTResponse), // REST response
}
impl Default for Message {
fn default() -> Self {
Message::None(())
}
}
// Casts to platform-wide messages
impl From<RESTRequest> for Message {
fn from(msg: RESTRequest) -> Self {
Message::RESTRequest(msg)
}
}
impl From<RESTResponse> for Message {
fn from(msg: RESTResponse) -> Self {
Message::RESTResponse(msg)
}
}
// Casts from platform-wide messages
impl GetRESTResponse for Message {
fn get_rest_response(&self) -> Option<RESTResponse> {
if let Message::RESTResponse(result) = self {
Some(result.clone())
} else {
None
}
}
}