/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rkyv-0.8.15/src/net.rs
Line | Count | Source |
1 | | //! Archived versions of network types. |
2 | | |
3 | | use core::net::{ |
4 | | IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, |
5 | | }; |
6 | | |
7 | | use munge::munge; |
8 | | |
9 | | use crate::{ |
10 | | primitive::{ArchivedU16, ArchivedU32}, |
11 | | Archive, Place, Portable, |
12 | | }; |
13 | | |
14 | | /// An archived [`Ipv4Addr`]. |
15 | | #[derive(Portable)] |
16 | | #[rkyv(crate)] |
17 | | #[cfg_attr(feature = "bytecheck", derive(bytecheck::CheckBytes))] |
18 | | #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] |
19 | | #[repr(transparent)] |
20 | | pub struct ArchivedIpv4Addr { |
21 | | octets: [u8; 4], |
22 | | } |
23 | | |
24 | | impl ArchivedIpv4Addr { |
25 | | /// Returns the four eight-bit integers that make up this address. |
26 | | #[inline] |
27 | 0 | pub const fn octets(&self) -> [u8; 4] { |
28 | 0 | self.octets |
29 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::octets Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::octets |
30 | | |
31 | | /// Returns an [`Ipv4Addr`] with the same value. |
32 | | #[inline] |
33 | 0 | pub const fn as_ipv4(&self) -> Ipv4Addr { |
34 | 0 | let octets = self.octets(); |
35 | 0 | Ipv4Addr::new(octets[0], octets[1], octets[2], octets[3]) |
36 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::as_ipv4 Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::as_ipv4 |
37 | | |
38 | | /// Returns `true` if this is a broadcast address (255.255.255.255). |
39 | | /// |
40 | | /// See [`Ipv4Addr::is_broadcast`] for more details. |
41 | | #[inline] |
42 | 0 | pub const fn is_broadcast(&self) -> bool { |
43 | 0 | self.as_ipv4().is_broadcast() |
44 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_broadcast Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_broadcast |
45 | | |
46 | | /// Returns `true` if this address is in a range designated for |
47 | | /// documentation. |
48 | | /// |
49 | | /// See [`Ipv4Addr::is_documentation`] for more details. |
50 | | #[inline] |
51 | 0 | pub const fn is_documentation(&self) -> bool { |
52 | 0 | self.as_ipv4().is_documentation() |
53 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_documentation Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_documentation |
54 | | |
55 | | /// Returns `true` if the address is link-local (169.254.0.0/16). |
56 | | /// |
57 | | /// See [`Ipv4Addr::is_link_local`] for more details. |
58 | | #[inline] |
59 | 0 | pub const fn is_link_local(&self) -> bool { |
60 | 0 | self.as_ipv4().is_link_local() |
61 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_link_local Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_link_local |
62 | | |
63 | | /// Returns `true` if this is a loopback address (127.0.0.0/8). |
64 | | /// |
65 | | /// See [`Ipv4Addr::is_loopback`] for more details. |
66 | | #[inline] |
67 | 0 | pub const fn is_loopback(&self) -> bool { |
68 | 0 | self.as_ipv4().is_loopback() |
69 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_loopback Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_loopback |
70 | | |
71 | | /// Returns `true` if this is a multicast address (224.0.0.0/4). |
72 | | /// |
73 | | /// See [`Ipv4Addr::is_multicast`] for more details. |
74 | | #[inline] |
75 | 0 | pub const fn is_multicast(&self) -> bool { |
76 | 0 | self.as_ipv4().is_multicast() |
77 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_multicast Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_multicast |
78 | | |
79 | | /// Returns `true` if this is a private address. |
80 | | /// |
81 | | /// See [`Ipv4Addr::is_private`] for more details. |
82 | | #[inline] |
83 | 0 | pub const fn is_private(&self) -> bool { |
84 | 0 | self.as_ipv4().is_private() |
85 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_private Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_private |
86 | | |
87 | | /// Returns `true` for the special 'unspecified' address (0.0.0.0). |
88 | | /// |
89 | | /// See [`Ipv4Addr::is_unspecified`] for more details. |
90 | | #[inline] |
91 | 0 | pub const fn is_unspecified(&self) -> bool { |
92 | 0 | self.as_ipv4().is_unspecified() |
93 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_unspecified Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::is_unspecified |
94 | | |
95 | | /// Converts this address to an IPv4-compatible |
96 | | /// [`IPv6` address](std::net::Ipv6Addr). |
97 | | /// |
98 | | /// See [`Ipv4Addr::to_ipv6_compatible`] for more |
99 | | /// details. |
100 | | #[inline] |
101 | | #[allow(clippy::wrong_self_convention)] |
102 | 0 | pub const fn to_ipv6_compatible(&self) -> Ipv6Addr { |
103 | 0 | self.as_ipv4().to_ipv6_compatible() |
104 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::to_ipv6_compatible Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::to_ipv6_compatible |
105 | | |
106 | | /// Converts this address to an IPv4-mapped |
107 | | /// [`IPv6` address](std::net::Ipv6Addr). |
108 | | /// |
109 | | /// See [`Ipv4Addr::to_ipv6_mapped`] for more details. |
110 | | #[inline] |
111 | | #[allow(clippy::wrong_self_convention)] |
112 | 0 | pub const fn to_ipv6_mapped(&self) -> Ipv6Addr { |
113 | 0 | self.as_ipv4().to_ipv6_mapped() |
114 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::to_ipv6_mapped Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::to_ipv6_mapped |
115 | | |
116 | | /// Emplaces an `ArchivedIpv4Addr` with the given octets into a place. |
117 | | #[inline] |
118 | 0 | pub fn emplace(octets: [u8; 4], out: Place<Self>) { |
119 | 0 | unsafe { |
120 | 0 | out.cast_unchecked::<[u8; 4]>().write(octets); |
121 | 0 | } |
122 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::emplace Unexecuted instantiation: <rkyv::net::ArchivedIpv4Addr>::emplace |
123 | | } |
124 | | |
125 | | /// An archived [`Ipv6Addr`]. |
126 | | #[derive(Portable)] |
127 | | #[rkyv(crate)] |
128 | | #[cfg_attr(feature = "bytecheck", derive(bytecheck::CheckBytes))] |
129 | | #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] |
130 | | #[repr(transparent)] |
131 | | pub struct ArchivedIpv6Addr { |
132 | | octets: [u8; 16], |
133 | | } |
134 | | |
135 | | impl ArchivedIpv6Addr { |
136 | | /// Returns the eight 16-bit segments that make up this address. |
137 | | #[inline] |
138 | 0 | pub const fn segments(&self) -> [u16; 8] { |
139 | 0 | [ |
140 | 0 | u16::from_be_bytes([self.octets[0], self.octets[1]]), |
141 | 0 | u16::from_be_bytes([self.octets[2], self.octets[3]]), |
142 | 0 | u16::from_be_bytes([self.octets[4], self.octets[5]]), |
143 | 0 | u16::from_be_bytes([self.octets[6], self.octets[7]]), |
144 | 0 | u16::from_be_bytes([self.octets[8], self.octets[9]]), |
145 | 0 | u16::from_be_bytes([self.octets[10], self.octets[11]]), |
146 | 0 | u16::from_be_bytes([self.octets[12], self.octets[13]]), |
147 | 0 | u16::from_be_bytes([self.octets[14], self.octets[15]]), |
148 | 0 | ] |
149 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::segments Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::segments |
150 | | |
151 | | /// Returns an [`Ipv6Addr`] with the same value. |
152 | | #[inline] |
153 | 0 | pub const fn as_ipv6(&self) -> Ipv6Addr { |
154 | 0 | let segments = self.segments(); |
155 | 0 | Ipv6Addr::new( |
156 | 0 | segments[0], |
157 | 0 | segments[1], |
158 | 0 | segments[2], |
159 | 0 | segments[3], |
160 | 0 | segments[4], |
161 | 0 | segments[5], |
162 | 0 | segments[6], |
163 | 0 | segments[7], |
164 | | ) |
165 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::as_ipv6 Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::as_ipv6 |
166 | | |
167 | | /// Returns `true` if this is a loopback address (::1). |
168 | | /// |
169 | | /// See [`Ipv6Addr::is_loopback()`](std::net::Ipv6Addr::is_loopback()) for |
170 | | /// more details. |
171 | | #[inline] |
172 | 0 | pub const fn is_loopback(&self) -> bool { |
173 | 0 | self.as_ipv6().is_loopback() |
174 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::is_loopback Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::is_loopback |
175 | | |
176 | | /// Returns `true` if this is a multicast address (ff00::/8). |
177 | | /// |
178 | | /// See [`Ipv6Addr::is_multicast()`](std::net::Ipv6Addr::is_multicast()) for |
179 | | /// more details. |
180 | | #[inline] |
181 | 0 | pub const fn is_multicast(&self) -> bool { |
182 | 0 | self.as_ipv6().is_multicast() |
183 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::is_multicast Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::is_multicast |
184 | | |
185 | | /// Returns `true` for the special 'unspecified' address (::). |
186 | | /// |
187 | | /// See [`Ipv6Addr::is_unspecified()`](std::net::Ipv6Addr::is_unspecified()) |
188 | | /// for more details. |
189 | | #[inline] |
190 | 0 | pub const fn is_unspecified(&self) -> bool { |
191 | 0 | self.as_ipv6().is_unspecified() |
192 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::is_unspecified Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::is_unspecified |
193 | | |
194 | | /// Returns the sixteen eight-bit integers the IPv6 address consists of. |
195 | | #[inline] |
196 | 0 | pub const fn octets(&self) -> [u8; 16] { |
197 | 0 | self.as_ipv6().octets() |
198 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::octets Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::octets |
199 | | |
200 | | /// Converts this address to an [`IPv4` address](std::net::Ipv4Addr). |
201 | | /// Returns [`None`] if this address is neither IPv4-compatible or |
202 | | /// IPv4-mapped. |
203 | | #[inline] |
204 | | #[allow(clippy::wrong_self_convention)] |
205 | 0 | pub const fn to_ipv4(&self) -> Option<Ipv4Addr> { |
206 | 0 | self.as_ipv6().to_ipv4() |
207 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::to_ipv4 Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::to_ipv4 |
208 | | |
209 | | /// Emplaces an `ArchivedIpv6Addr` with the given octets into a place. |
210 | | #[inline] |
211 | 0 | pub fn emplace(octets: [u8; 16], out: Place<Self>) { |
212 | 0 | unsafe { |
213 | 0 | out.cast_unchecked::<[u8; 16]>().write(octets); |
214 | 0 | } |
215 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::emplace Unexecuted instantiation: <rkyv::net::ArchivedIpv6Addr>::emplace |
216 | | } |
217 | | |
218 | | /// An archived [`IpAddr`]. |
219 | | #[derive(Portable)] |
220 | | #[rkyv(crate)] |
221 | | #[cfg_attr(feature = "bytecheck", derive(bytecheck::CheckBytes))] |
222 | | #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
223 | | #[repr(u8)] |
224 | | pub enum ArchivedIpAddr { |
225 | | /// An IPv4 address. |
226 | | V4(ArchivedIpv4Addr), |
227 | | /// An IPv6 address. |
228 | | V6(ArchivedIpv6Addr), |
229 | | } |
230 | | |
231 | | impl ArchivedIpAddr { |
232 | | /// Returns `true` if this address is an [`IPv4` |
233 | | /// address](std::net::IpAddr::V4), and `false` otherwise. |
234 | | #[inline] |
235 | 0 | pub const fn is_ipv4(&self) -> bool { |
236 | 0 | matches!(self, ArchivedIpAddr::V4(_)) |
237 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_ipv4 Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_ipv4 |
238 | | |
239 | | /// Returns `true` if this address is an [`IPv6` |
240 | | /// address](std::net::IpAddr::V6), and `false` otherwise. |
241 | | #[inline] |
242 | 0 | pub const fn is_ipv6(&self) -> bool { |
243 | 0 | matches!(self, ArchivedIpAddr::V6(_)) |
244 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_ipv6 Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_ipv6 |
245 | | |
246 | | /// Returns an [`IpAddr`] with the same value. |
247 | | #[inline] |
248 | 0 | pub const fn as_ipaddr(&self) -> IpAddr { |
249 | 0 | match self { |
250 | 0 | ArchivedIpAddr::V4(ipv4) => IpAddr::V4(ipv4.as_ipv4()), |
251 | 0 | ArchivedIpAddr::V6(ipv6) => IpAddr::V6(ipv6.as_ipv6()), |
252 | | } |
253 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::as_ipaddr Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::as_ipaddr |
254 | | |
255 | | /// Returns `true` if this is a loopback address. |
256 | | /// |
257 | | /// See [`IpAddr::is_loopback()`](std::net::IpAddr::is_loopback()) for more |
258 | | /// details. |
259 | | #[inline] |
260 | 0 | pub const fn is_loopback(&self) -> bool { |
261 | 0 | match self { |
262 | 0 | ArchivedIpAddr::V4(ip) => ip.is_loopback(), |
263 | 0 | ArchivedIpAddr::V6(ip) => ip.is_loopback(), |
264 | | } |
265 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_loopback Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_loopback |
266 | | |
267 | | /// Returns `true` if this is a multicast address. |
268 | | /// |
269 | | /// See [`IpAddr::is_multicast()`](std::net::IpAddr::is_multicast()) for |
270 | | /// more details. |
271 | | #[inline] |
272 | 0 | pub const fn is_multicast(&self) -> bool { |
273 | 0 | match self { |
274 | 0 | ArchivedIpAddr::V4(ip) => ip.is_multicast(), |
275 | 0 | ArchivedIpAddr::V6(ip) => ip.is_multicast(), |
276 | | } |
277 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_multicast Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_multicast |
278 | | |
279 | | /// Returns `true` for the special 'unspecified' address. |
280 | | /// |
281 | | /// See [`IpAddr::is_unspecified()`](std::net::IpAddr::is_unspecified()) for |
282 | | /// more details. |
283 | | #[inline] |
284 | 0 | pub const fn is_unspecified(&self) -> bool { |
285 | 0 | match self { |
286 | 0 | ArchivedIpAddr::V4(ip) => ip.is_unspecified(), |
287 | 0 | ArchivedIpAddr::V6(ip) => ip.is_unspecified(), |
288 | | } |
289 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_unspecified Unexecuted instantiation: <rkyv::net::ArchivedIpAddr>::is_unspecified |
290 | | } |
291 | | |
292 | | /// An archived [`SocketAddrV4`]. |
293 | | #[derive( |
294 | | Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, Portable, PartialOrd, |
295 | | )] |
296 | | #[cfg_attr(feature = "bytecheck", derive(bytecheck::CheckBytes))] |
297 | | #[rkyv(crate)] |
298 | | #[repr(C)] |
299 | | pub struct ArchivedSocketAddrV4 { |
300 | | ip: ArchivedIpv4Addr, |
301 | | port: ArchivedU16, |
302 | | } |
303 | | |
304 | | impl ArchivedSocketAddrV4 { |
305 | | /// Returns the IP address associated with this socket address. |
306 | | #[inline] |
307 | 0 | pub const fn ip(&self) -> &ArchivedIpv4Addr { |
308 | 0 | &self.ip |
309 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::ip Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::ip |
310 | | |
311 | | /// Returns the port number associated with this socket address. |
312 | | #[inline] |
313 | 0 | pub const fn port(&self) -> u16 { |
314 | 0 | self.port.to_native() |
315 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::port Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::port |
316 | | |
317 | | /// Returns a [`SocketAddrV4`] with the same value. |
318 | | #[inline] |
319 | 0 | pub fn as_socket_addr_v4(&self) -> SocketAddrV4 { |
320 | 0 | SocketAddrV4::new(self.ip().as_ipv4(), self.port()) |
321 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::as_socket_addr_v4 Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::as_socket_addr_v4 |
322 | | |
323 | | /// Emplaces an `ArchivedSocketAddrV4` of the given `value` into a place. |
324 | | #[inline] |
325 | 0 | pub fn emplace(value: &SocketAddrV4, out: Place<Self>) { |
326 | 0 | munge!(let ArchivedSocketAddrV4 { ip, port } = out); |
327 | 0 | value.ip().resolve((), ip); |
328 | 0 | value.port().resolve((), port); |
329 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::emplace Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV4>::emplace |
330 | | } |
331 | | |
332 | | /// An archived [`SocketAddrV6`]. |
333 | | #[derive( |
334 | | Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, Portable, PartialOrd, |
335 | | )] |
336 | | #[cfg_attr(feature = "bytecheck", derive(bytecheck::CheckBytes))] |
337 | | #[rkyv(crate)] |
338 | | #[repr(C)] |
339 | | pub struct ArchivedSocketAddrV6 { |
340 | | ip: ArchivedIpv6Addr, |
341 | | port: ArchivedU16, |
342 | | flowinfo: ArchivedU32, |
343 | | scope_id: ArchivedU32, |
344 | | } |
345 | | |
346 | | impl ArchivedSocketAddrV6 { |
347 | | /// Returns the flow information associated with this address. |
348 | | /// |
349 | | /// See [`SocketAddrV6::flowinfo()`](std::net::SocketAddrV6::flowinfo()) for |
350 | | /// more details. |
351 | | #[inline] |
352 | 0 | pub const fn flowinfo(&self) -> u32 { |
353 | 0 | self.flowinfo.to_native() |
354 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::flowinfo Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::flowinfo |
355 | | |
356 | | /// Returns the IP address associated with this socket address. |
357 | | #[inline] |
358 | 0 | pub const fn ip(&self) -> &ArchivedIpv6Addr { |
359 | 0 | &self.ip |
360 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::ip Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::ip |
361 | | |
362 | | /// Returns the port number associated with this socket address. |
363 | | #[inline] |
364 | 0 | pub const fn port(&self) -> u16 { |
365 | 0 | self.port.to_native() |
366 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::port Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::port |
367 | | |
368 | | /// Returns the scope ID associated with this address. |
369 | | /// |
370 | | /// See [`SocketAddrV6::scope_id()`](std::net::SocketAddrV6::scope_id()) for |
371 | | /// more details. |
372 | | #[inline] |
373 | 0 | pub const fn scope_id(&self) -> u32 { |
374 | 0 | self.scope_id.to_native() |
375 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::scope_id Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::scope_id |
376 | | |
377 | | /// Returns a [`SocketAddrV6`] with the same value. |
378 | | #[inline] |
379 | 0 | pub fn as_socket_addr_v6(&self) -> SocketAddrV6 { |
380 | 0 | SocketAddrV6::new( |
381 | 0 | self.ip().as_ipv6(), |
382 | 0 | self.port(), |
383 | 0 | self.flowinfo(), |
384 | 0 | self.scope_id(), |
385 | | ) |
386 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::as_socket_addr_v6 Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::as_socket_addr_v6 |
387 | | |
388 | | /// Emplaces an `ArchivedSocketAddrV6` of the given `value` into a place. |
389 | | #[inline] |
390 | 0 | pub fn emplace(value: &SocketAddrV6, out: Place<Self>) { |
391 | 0 | munge!(let ArchivedSocketAddrV6 { ip, port, flowinfo, scope_id } = out); |
392 | 0 | value.ip().resolve((), ip); |
393 | 0 | value.port().resolve((), port); |
394 | 0 | value.flowinfo().resolve((), flowinfo); |
395 | 0 | value.scope_id().resolve((), scope_id); |
396 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::emplace Unexecuted instantiation: <rkyv::net::ArchivedSocketAddrV6>::emplace |
397 | | } |
398 | | |
399 | | /// An archived [`SocketAddr`]. |
400 | | #[derive(Portable)] |
401 | | #[rkyv(crate)] |
402 | | #[cfg_attr(feature = "bytecheck", derive(bytecheck::CheckBytes))] |
403 | | #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] |
404 | | #[repr(u8)] |
405 | | pub enum ArchivedSocketAddr { |
406 | | /// An IPv4 socket address. |
407 | | V4(ArchivedSocketAddrV4), |
408 | | /// An IPv6 socket address. |
409 | | V6(ArchivedSocketAddrV6), |
410 | | } |
411 | | |
412 | | impl ArchivedSocketAddr { |
413 | | /// Returns the port number associated with this socket address. |
414 | | #[inline] |
415 | 0 | pub fn port(&self) -> u16 { |
416 | 0 | match self { |
417 | 0 | ArchivedSocketAddr::V4(addr) => addr.port(), |
418 | 0 | ArchivedSocketAddr::V6(addr) => addr.port(), |
419 | | } |
420 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::port Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::port |
421 | | |
422 | | /// Returns `true` if the [IP address](std::net::IpAddr) in this |
423 | | /// `ArchivedSocketAddr` is an [`IPv4` address](std::net::IpAddr::V4), |
424 | | /// and `false` otherwise. |
425 | | #[inline] |
426 | 0 | pub fn is_ipv4(&self) -> bool { |
427 | 0 | matches!(self, ArchivedSocketAddr::V4(_)) |
428 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::is_ipv4 Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::is_ipv4 |
429 | | |
430 | | /// Returns `true` if the [IP address](std::net::IpAddr) in this |
431 | | /// `ArchivedSocketAddr` is an [`IPv6` address](std::net::IpAddr::V6), |
432 | | /// and `false` otherwise. |
433 | | #[inline] |
434 | 0 | pub fn is_ipv6(&self) -> bool { |
435 | 0 | matches!(self, ArchivedSocketAddr::V6(_)) |
436 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::is_ipv6 Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::is_ipv6 |
437 | | |
438 | | /// Returns a [`SocketAddr`] with the same value. |
439 | | #[inline] |
440 | 0 | pub fn as_socket_addr(&self) -> SocketAddr { |
441 | 0 | match self { |
442 | 0 | ArchivedSocketAddr::V4(addr) => { |
443 | 0 | SocketAddr::V4(addr.as_socket_addr_v4()) |
444 | | } |
445 | 0 | ArchivedSocketAddr::V6(addr) => { |
446 | 0 | SocketAddr::V6(addr.as_socket_addr_v6()) |
447 | | } |
448 | | } |
449 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::as_socket_addr Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::as_socket_addr |
450 | | |
451 | | /// Returns the IP address associated with this socket address. |
452 | | #[inline] |
453 | 0 | pub fn ip(&self) -> IpAddr { |
454 | 0 | match self { |
455 | 0 | ArchivedSocketAddr::V4(addr) => IpAddr::V4(addr.ip().as_ipv4()), |
456 | 0 | ArchivedSocketAddr::V6(addr) => IpAddr::V6(addr.ip().as_ipv6()), |
457 | | } |
458 | 0 | } Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::ip Unexecuted instantiation: <rkyv::net::ArchivedSocketAddr>::ip |
459 | | } |