Skip to content

Commit

Permalink
Merge pull request #140 from achanda/contains-inline
Browse files Browse the repository at this point in the history
Always inline the contains function
  • Loading branch information
achanda committed Apr 5, 2021
2 parents 1410809 + 9921661 commit fe9f1ba
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions src/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit fe9f1ba

Please sign in to comment.