@@ -113,13 +113,14 @@ impl<'a> DNSPattern<'a> {
113
113
}
114
114
}
115
115
116
- #[ derive( Copy , Clone , Debug , PartialEq ) ]
116
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
117
117
pub struct IPAddress ( IpAddr ) ;
118
118
119
119
/// An `IPAddress` represents an IP address as defined in [RFC 5280 4.2.1.6].
120
120
///
121
121
/// [RFC 5280 4.2.1.6]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6
122
122
impl IPAddress {
123
+ #[ allow( clippy:: should_implement_trait) ]
123
124
pub fn from_str ( s : & str ) -> Option < Self > {
124
125
IpAddr :: from_str ( s) . ok ( ) . map ( Self :: from)
125
126
}
@@ -175,7 +176,7 @@ impl IPAddress {
175
176
pub fn mask ( & self , prefix : u8 ) -> Self {
176
177
match self . 0 {
177
178
IpAddr :: V4 ( a) => {
178
- let prefix = 32u8 . checked_sub ( prefix) . unwrap_or ( 0 ) . into ( ) ;
179
+ let prefix = 32u8 . saturating_sub ( prefix) . into ( ) ;
179
180
let masked = u32:: from_be_bytes ( a. octets ( ) )
180
181
& u32:: MAX
181
182
. checked_shr ( prefix)
@@ -185,7 +186,7 @@ impl IPAddress {
185
186
Self :: from_bytes ( & masked. to_be_bytes ( ) ) . unwrap ( )
186
187
}
187
188
IpAddr :: V6 ( a) => {
188
- let prefix = 128u8 . checked_sub ( prefix) . unwrap_or ( 0 ) . into ( ) ;
189
+ let prefix = 128u8 . saturating_sub ( prefix) . into ( ) ;
189
190
let masked = u128:: from_be_bytes ( a. octets ( ) )
190
191
& u128:: MAX
191
192
. checked_shr ( prefix)
@@ -204,7 +205,7 @@ impl From<IpAddr> for IPAddress {
204
205
}
205
206
}
206
207
207
- #[ derive( Debug , PartialEq ) ]
208
+ #[ derive( Debug , PartialEq , Eq ) ]
208
209
pub struct IPRange {
209
210
address : IPAddress ,
210
211
prefix : u8 ,
0 commit comments