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
use core::fmt::Debug;
use embedded_time::Clock;
use kwap_common::prelude::*;
use kwap_msg::{Id, Opt, OptNumber, Token};
use no_std_net::SocketAddr;
#[cfg(feature = "alloc")]
use std_alloc::{collections::BTreeMap, vec::Vec};
use crate::net::Socket;
use crate::time::Stamped;
pub trait Platform: Sized + 'static + core::fmt::Debug {
  
  type MessagePayload: Array<Item = u8> + Clone + Debug;
  
  type MessageOptionBytes: Array<Item = u8> + 'static + Clone + Debug;
  
  type MessageOptions: Array<Item = Opt<Self::MessageOptionBytes>> + Clone + Debug;
  
  type MessageIdHistory: Array<Item = Stamped<Self::Clock, Id>> + Clone + Debug;
  
  type MessageIdHistoryBySocket: Map<SocketAddr, Self::MessageIdHistory> + Clone + Debug;
  
  type MessageTokenHistory: Array<Item = Stamped<Self::Clock, Token>> + Clone + Debug;
  
  type MessageTokenHistoryBySocket: Map<SocketAddr, Self::MessageTokenHistory> + Clone + Debug;
  
  type NumberedOptions: Array<Item = (OptNumber, Opt<Self::MessageOptionBytes>)> + Clone + Debug;
  
  type Clock: Clock<T = u64>;
  
  type Socket: Socket;
}
#[derive(Debug, Clone, Copy)]
pub struct Retryable<P: Platform, T>(pub T, pub crate::retry::RetryTimer<P::Clock>);
impl<P: Platform, T> Retryable<P, T> {
  
  pub fn unwrap(self) -> T {
    self.0
  }
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Copy)]
pub struct Alloc<Clk, Sock>(core::marker::PhantomData<(Clk, Sock)>)
  where Clk: Clock<T = u64> + 'static,
        Sock: Socket + 'static;
#[cfg(feature = "alloc")]
impl<Clk: Clock<T = u64> + 'static, Sock: Socket + 'static> core::fmt::Debug for Alloc<Clk, Sock> {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    write!(f, "Alloc::<_, _>(_)")
  }
}
#[cfg(feature = "alloc")]
impl<Clk: Clock<T = u64> + 'static, Sock: Socket + 'static> Clone for Alloc<Clk, Sock> {
  fn clone(&self) -> Self {
    Self(Default::default())
  }
}
#[cfg(feature = "alloc")]
impl<Clk: Clock<T = u64> + Debug + 'static, Sock: Socket + 'static> Platform for Alloc<Clk, Sock> {
  type MessagePayload = Vec<u8>;
  type MessageOptionBytes = Vec<u8>;
  type MessageOptions = Vec<Opt<Vec<u8>>>;
  type MessageIdHistory = Vec<Stamped<Self::Clock, Id>>;
  type MessageTokenHistory = Vec<Stamped<Self::Clock, Token>>;
  type MessageIdHistoryBySocket = BTreeMap<SocketAddr, Self::MessageIdHistory>;
  type MessageTokenHistoryBySocket = BTreeMap<SocketAddr, Self::MessageTokenHistory>;
  type NumberedOptions = Vec<(OptNumber, Opt<Vec<u8>>)>;
  type Clock = Clk;
  type Socket = Sock;
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub type Std = Alloc<crate::std::Clock, std::net::UdpSocket>;
pub type Message<P> = kwap_msg::Message<<P as Platform>::MessagePayload,
                                        <P as Platform>::MessageOptionBytes,
                                        <P as Platform>::MessageOptions>;