async_coap/send_desc/
inspect.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 Inspect<SD, IC> {}
19impl<SD: SendDescMulticast, IC> SendDescMulticast for Inspect<SD, IC> {}
20
21/// Combinator for Send Descriptors created by [`SendDescExt::inspect`].
22#[derive(Debug)]
23pub struct Inspect<SD, F> {
24    pub(super) inner: SD,
25    pub(super) inspect: F,
26}
27
28impl<SD, F, IC, R> SendDesc<IC, R> for Inspect<SD, F>
29where
30    SD: SendDesc<IC, R> + Send,
31    IC: InboundContext,
32    R: Send,
33    F: FnMut(&dyn InboundContext<SocketAddr = IC::SocketAddr>) + Send,
34{
35    send_desc_passthru_timing!(inner);
36    send_desc_passthru_options!(inner);
37    send_desc_passthru_payload!(inner);
38    send_desc_passthru_supports_option!(inner);
39
40    fn handler(&mut self, context: Result<&IC, Error>) -> Result<ResponseStatus<R>, Error> {
41        if let Some(context) = context.ok() {
42            (self.inspect)(context);
43        }
44        self.inner.handler(context)
45    }
46}