async_coap/send_desc/
add_option.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::*;
17use crate::option::OptionValue;
18
19impl<SD: SendDescUnicast, K, I: Send, IC> SendDescUnicast for AddOption<SD, K, I, IC> {}
20impl<SD: SendDescMulticast, K, I: Send, IC> SendDescMulticast for AddOption<SD, K, I, IC> {}
21
22/// Combinator for Send Descriptors created by [`SendDescExt::add_option`].
23#[derive(Debug)]
24pub struct AddOption<SD, K, I: Send, IC> {
25    pub(super) inner: SD,
26    pub(super) key: OptionKey<K>,
27    pub(super) viter: I,
28    pub(super) phantom: PhantomData<IC>,
29}
30
31impl<'a, SD, IC, R, K, I> SendDesc<IC, R> for AddOption<SD, K, I, IC>
32where
33    SD: SendDesc<IC, R> + Send,
34    IC: InboundContext,
35    R: Send,
36    I: IntoIterator<Item = K> + Clone + Send,
37    K: Into<OptionValue<'a>>,
38{
39    send_desc_passthru_timing!(inner);
40    send_desc_passthru_handler!(inner, R);
41    send_desc_passthru_payload!(inner);
42
43    fn write_options(
44        &self,
45        msg: &mut dyn OptionInsert,
46        socket_addr: &IC::SocketAddr,
47        start: Bound<OptionNumber>,
48        end: Bound<OptionNumber>,
49    ) -> Result<(), Error> {
50        write_options!((msg, socket_addr, start, end, self.inner) {
51            self.key => self.viter.clone(),
52        })
53    }
54}