s2n_quic_core/inet/unspecified.rs
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4/// A trait to determine if the value is left unspecified,
5/// usually containing the default value.
6///
7/// See: <https://en.wikipedia.org/wiki/IPv6_address#Unspecified_address>
8pub trait Unspecified: Sized {
9 /// Returns true if the value is unspecified
10 fn is_unspecified(&self) -> bool;
11
12 /// Coerce a potentially unspecified value into an `Option<Self>`
13 fn filter_unspecified(self) -> Option<Self> {
14 if self.is_unspecified() {
15 None
16 } else {
17 Some(self)
18 }
19 }
20}
21
22macro_rules! unspecified_integer {
23 ($name:ident) => {
24 impl Unspecified for s2n_codec::zerocopy::$name {
25 fn is_unspecified(&self) -> bool {
26 Self::default().eq(self)
27 }
28 }
29 };
30}
31
32unspecified_integer!(U16);
33unspecified_integer!(U32);
34unspecified_integer!(U64);
35unspecified_integer!(U128);