Merge pull request #140 from achanda/contains-inline

Always inline the contains function
This commit is contained in:
Abhishek Chanda
2021-04-05 14:25:30 -05:00
committed by GitHub
4 changed files with 4 additions and 1 deletions

View File

@ -16,7 +16,7 @@ serde = { version = "1", optional = true }
[dev-dependencies]
serde_json = "1.0"
serde_derive = "1"
criterion = "0.3.0"
criterion = {version = "0.3.4", features= ["html_reports"]}
[badges]
travis-ci = { repository = "achanda/ipnetwork" }

View File

@ -163,6 +163,7 @@ impl Ipv4Network {
/// assert!(net.contains(Ipv4Addr::new(127, 0, 0, 70)));
/// assert!(!net.contains(Ipv4Addr::new(127, 0, 1, 70)));
/// ```
#[inline]
pub fn contains(self, ip: Ipv4Addr) -> bool {
let mask = !(0xffff_ffff as u64 >> self.prefix) as u32;
let net = u32::from(self.addr) & mask;

View File

@ -174,6 +174,7 @@ impl Ipv6Network {
/// assert!(net.contains(Ipv6Addr::new(0xff01, 0, 0, 0, 0, 0, 0, 0x1)));
/// assert!(!net.contains(Ipv6Addr::new(0xffff, 0, 0, 0, 0, 0, 0, 0x1)));
/// ```
#[inline]
pub fn contains(&self, ip: Ipv6Addr) -> bool {
let a = self.addr.segments();
let b = ip.segments();

View File

@ -228,6 +228,7 @@ impl IpNetwork {
/// assert!(!net.contains(ip2));
/// assert!(!net.contains(ip4));
/// ```
#[inline]
pub fn contains(&self, ip: IpAddr) -> bool {
match (*self, ip) {
(IpNetwork::V4(net), IpAddr::V4(ip)) => net.contains(ip),