1#![doc = include_str!("../README.md")]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![forbid(unsafe_code)]
4#![deny(missing_docs)]
5#![allow(unexpected_cfgs)]
6#![cfg_attr(docsrs, feature(doc_cfg))]
7#![cfg_attr(docsrs, allow(unused_attributes))]
8#![allow(clippy::needless_return)]
9#![allow(unreachable_code)]
10
11#[cfg(feature = "slab")]
12pub use slab;
13pub use srv::*;
14pub use txt::*;
15
16pub mod error;
18
19pub mod server;
21
22pub mod client;
24
25pub mod proto {
27 pub use super::srv::Srv;
28 pub use super::txt::{Str, Strings, Txt};
29 pub use dns_protocol::{
30 Cursor, Deserialize, Flags, Header, Label, LabelSegment, Message, MessageType, Opcode,
31 Question, ResourceRecord, ResourceType, ResponseCode, Serialize,
32 };
33}
34
35mod srv;
36mod txt;
37
38#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
40pub struct ConnectionHandle(pub usize);
41
42impl From<ConnectionHandle> for usize {
43 fn from(x: ConnectionHandle) -> Self {
44 x.0
45 }
46}
47
48impl core::fmt::Display for ConnectionHandle {
49 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
50 write!(f, "{}", self.0)
51 }
52}
53
54pub trait Pool<V> {
56 type Error: core::error::Error;
58
59 type Iter<'a>: Iterator<Item = (usize, &'a V)>
61 where
62 Self: 'a,
63 V: 'a;
64
65 fn new() -> Self;
67
68 fn with_capacity(capacity: usize) -> Result<Self, Self::Error>
72 where
73 Self: Sized;
74
75 fn vacant_key(&self) -> Result<usize, Self::Error>;
79
80 fn is_empty(&self) -> bool;
82
83 fn len(&self) -> usize;
85
86 fn get(&self, key: usize) -> Option<&V>;
91
92 fn get_mut(&mut self, key: usize) -> Option<&mut V>;
97
98 fn insert(&mut self, value: V) -> Result<usize, Self::Error>;
105
106 fn try_remove(&mut self, key: usize) -> Option<V>;
112
113 fn iter(&self) -> Self::Iter<'_>;
115}
116
117#[cfg(feature = "slab")]
118impl<T> Pool<T> for slab::Slab<T> {
119 type Error = core::convert::Infallible;
120
121 type Iter<'a>
122 = slab::Iter<'a, T>
123 where
124 Self: 'a;
125
126 fn new() -> Self {
127 slab::Slab::new()
128 }
129
130 fn with_capacity(capacity: usize) -> Result<Self, Self::Error>
131 where
132 Self: Sized,
133 {
134 Ok(slab::Slab::with_capacity(capacity))
135 }
136
137 fn vacant_key(&self) -> Result<usize, Self::Error> {
138 Ok(slab::Slab::vacant_key(self))
139 }
140
141 fn is_empty(&self) -> bool {
142 slab::Slab::is_empty(self)
143 }
144
145 fn len(&self) -> usize {
146 slab::Slab::len(self)
147 }
148
149 fn get(&self, key: usize) -> Option<&T> {
150 slab::Slab::get(self, key)
151 }
152
153 fn get_mut(&mut self, key: usize) -> Option<&mut T> {
154 slab::Slab::get_mut(self, key)
155 }
156
157 fn insert(&mut self, value: T) -> Result<usize, Self::Error> {
158 Ok(slab::Slab::insert(self, value))
159 }
160
161 fn try_remove(&mut self, key: usize) -> Option<T> {
162 slab::Slab::try_remove(self, key)
163 }
164
165 fn iter(&self) -> Self::Iter<'_> {
166 slab::Slab::iter(self)
167 }
168}