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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use super::*;
use crate::message::OwnedImmutableMessage;
impl<SD: SendDescUnicast> SendDescUnicast for EmitAnyResponse<SD> {}
impl<SD: SendDescMulticast> SendDescMulticast for EmitAnyResponse<SD> {}
#[derive(Debug)]
pub struct EmitAnyResponse<SD> {
pub(super) inner: SD,
}
impl<SD> EmitAnyResponse<SD> {
pub(super) fn new(inner: SD) -> EmitAnyResponse<SD> {
EmitAnyResponse { inner }
}
}
impl<SD, IC> SendDesc<IC, OwnedImmutableMessage> for EmitAnyResponse<SD>
where
SD: SendDesc<IC, ()> + Send,
IC: InboundContext,
{
send_desc_passthru_timing!(inner);
send_desc_passthru_options!(inner);
send_desc_passthru_payload!(inner);
send_desc_passthru_supports_option!(inner);
fn handler(
&mut self,
context: Result<&IC, Error>,
) -> Result<ResponseStatus<OwnedImmutableMessage>, Error> {
let msg = context.ok().map(|x| x.message());
match (self.inner.handler(context), msg) {
(_, Some(msg)) => Ok(ResponseStatus::Done(msg.to_owned())),
(Ok(ResponseStatus::SendNext), None) => Ok(ResponseStatus::SendNext),
(Ok(ResponseStatus::Continue), None) => Ok(ResponseStatus::Continue),
(Ok(ResponseStatus::Done(())), None) => unreachable!(),
(Err(e), None) => Err(e),
}
}
}
#[derive(Debug)]
pub struct EmitSuccessfulResponse<SD> {
pub(super) inner: SD,
}
impl<SD> EmitSuccessfulResponse<SD> {
pub(super) fn new(inner: SD) -> EmitSuccessfulResponse<SD> {
EmitSuccessfulResponse { inner }
}
}
impl<SD, IC> SendDesc<IC, OwnedImmutableMessage> for EmitSuccessfulResponse<SD>
where
SD: SendDesc<IC, ()> + Send,
IC: InboundContext,
{
send_desc_passthru_timing!(inner);
send_desc_passthru_options!(inner);
send_desc_passthru_payload!(inner);
send_desc_passthru_supports_option!(inner);
fn handler(
&mut self,
context: Result<&IC, Error>,
) -> Result<ResponseStatus<OwnedImmutableMessage>, Error> {
let msg = context.ok().map(|x| x.message());
match (self.inner.handler(context), msg) {
(Err(e), _) => Err(e),
(_, Some(msg)) => Ok(ResponseStatus::Done(msg.to_owned())),
(Ok(ResponseStatus::SendNext), None) => Ok(ResponseStatus::SendNext),
(Ok(ResponseStatus::Continue), None) => Ok(ResponseStatus::Continue),
(Ok(ResponseStatus::Done(())), None) => unreachable!(),
}
}
}
impl<SD: SendDescUnicast> SendDescUnicast for EmitMsgCode<SD> {}
impl<SD: SendDescMulticast> SendDescMulticast for EmitMsgCode<SD> {}
#[derive(Debug)]
pub struct EmitMsgCode<SD> {
pub(super) inner: SD,
}
impl<SD> EmitMsgCode<SD> {
pub(super) fn new(inner: SD) -> EmitMsgCode<SD> {
EmitMsgCode { inner }
}
}
impl<SD, IC> SendDesc<IC, MsgCode> for EmitMsgCode<SD>
where
SD: SendDesc<IC, ()> + Send,
IC: InboundContext,
{
send_desc_passthru_timing!(inner);
send_desc_passthru_options!(inner);
send_desc_passthru_payload!(inner);
send_desc_passthru_supports_option!(inner);
fn handler(&mut self, context: Result<&IC, Error>) -> Result<ResponseStatus<MsgCode>, Error> {
let msg_code = context.ok().map(|x| x.message().msg_code());
self.inner.handler(context).map(|x| match (x, msg_code) {
(ResponseStatus::SendNext, _) => ResponseStatus::SendNext,
(_, Some(msg)) => ResponseStatus::Done(msg.to_owned()),
(_, _) => unreachable!(),
})
}
}