async_coap/send_desc/
payload.rs

1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15
16use super::*;
17
18impl<SD: SendDescUnicast, IC> SendDescUnicast for PayloadWriter<SD, IC> {}
19impl<SD: SendDescMulticast, IC> SendDescMulticast for PayloadWriter<SD, IC> {}
20
21/// Combinator for Send Descriptors created by [`SendDescExt::payload_writer`].
22#[derive(Debug)]
23pub struct PayloadWriter<SD, F> {
24    pub(super) inner: SD,
25    pub(super) writer: F,
26}
27
28impl<SD, F, IC, R> SendDesc<IC, R> for PayloadWriter<SD, F>
29where
30    SD: SendDesc<IC, R> + Send,
31    IC: InboundContext,
32    R: Send,
33    F: Fn(&mut dyn MessageWrite) -> Result<(), Error> + Send,
34{
35    send_desc_passthru_timing!(inner);
36    send_desc_passthru_options!(inner);
37    send_desc_passthru_handler!(inner, R);
38
39    fn write_payload(
40        &self,
41        msg: &mut dyn MessageWrite,
42        _socket_addr: &IC::SocketAddr,
43    ) -> Result<(), Error> {
44        (self.writer)(msg)
45    }
46}