Skip to content

Commit

Permalink
Add a few helper methods to detect IP family (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker authored Jul 18, 2024
1 parent f37a7aa commit 7dacd26
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ipnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ impl IpNet {
(_, _) => false,
}
}

/// Return `true` if this is an IPv4 network.
pub const fn is_ipv4(&self) -> bool {
matches!(self, IpNet::V4(_))
}

/// Return `true` if this is an IPv6 network.
pub const fn is_ipv6(&self) -> bool {
matches!(self, IpNet::V6(_))
}
}

impl From<Ipv4Net> for IpNet {
Expand Down

0 comments on commit 7dacd26

Please sign in to comment.