Skip to main content

over_there/core/msg/content/
mod.rs

1pub mod reply;
2pub mod request;
3
4pub use reply::{Reply, ReplyError};
5pub use request::{
6    LazilyTransformedRequest, Request, TransformRequestError, TransformRule,
7};
8
9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11
12#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
13#[serde(untagged)]
14pub enum Content {
15    Request(Request),
16    Reply(Reply),
17}
18
19impl Content {
20    pub fn into_request(self) -> Option<Request> {
21        match self {
22            Self::Request(x) => Some(x),
23            Self::Reply(_) => None,
24        }
25    }
26
27    pub fn into_reply(self) -> Option<Reply> {
28        match self {
29            Self::Request(_) => None,
30            Self::Reply(x) => Some(x),
31        }
32    }
33
34    pub fn into_reply_error(self) -> Option<ReplyError> {
35        match self.into_reply() {
36            Some(Reply::Error(x)) => Some(x),
37            _ => None,
38        }
39    }
40}
41
42impl crate::core::SchemaInfo for Content {}
43
44impl From<Request> for Content {
45    fn from(request: Request) -> Self {
46        Self::Request(request)
47    }
48}
49
50impl From<Reply> for Content {
51    fn from(reply: Reply) -> Self {
52        Self::Reply(reply)
53    }
54}
55
56impl From<ReplyError> for Content {
57    fn from(reply_error: ReplyError) -> Self {
58        Self::from(Reply::Error(reply_error))
59    }
60}