mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-16 08:48:51 +00:00
Merge pull request #140 from achanda/contains-inline
Always inline the contains function
This commit is contained in:
@ -16,7 +16,7 @@ serde = { version = "1", optional = true }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_derive = "1"
|
serde_derive = "1"
|
||||||
criterion = "0.3.0"
|
criterion = {version = "0.3.4", features= ["html_reports"]}
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "achanda/ipnetwork" }
|
travis-ci = { repository = "achanda/ipnetwork" }
|
||||||
|
@ -163,6 +163,7 @@ impl Ipv4Network {
|
|||||||
/// assert!(net.contains(Ipv4Addr::new(127, 0, 0, 70)));
|
/// assert!(net.contains(Ipv4Addr::new(127, 0, 0, 70)));
|
||||||
/// assert!(!net.contains(Ipv4Addr::new(127, 0, 1, 70)));
|
/// assert!(!net.contains(Ipv4Addr::new(127, 0, 1, 70)));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
pub fn contains(self, ip: Ipv4Addr) -> bool {
|
pub fn contains(self, ip: Ipv4Addr) -> bool {
|
||||||
let mask = !(0xffff_ffff as u64 >> self.prefix) as u32;
|
let mask = !(0xffff_ffff as u64 >> self.prefix) as u32;
|
||||||
let net = u32::from(self.addr) & mask;
|
let net = u32::from(self.addr) & mask;
|
||||||
|
@ -174,6 +174,7 @@ impl Ipv6Network {
|
|||||||
/// assert!(net.contains(Ipv6Addr::new(0xff01, 0, 0, 0, 0, 0, 0, 0x1)));
|
/// 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)));
|
/// assert!(!net.contains(Ipv6Addr::new(0xffff, 0, 0, 0, 0, 0, 0, 0x1)));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
pub fn contains(&self, ip: Ipv6Addr) -> bool {
|
pub fn contains(&self, ip: Ipv6Addr) -> bool {
|
||||||
let a = self.addr.segments();
|
let a = self.addr.segments();
|
||||||
let b = ip.segments();
|
let b = ip.segments();
|
||||||
|
@ -228,6 +228,7 @@ impl IpNetwork {
|
|||||||
/// assert!(!net.contains(ip2));
|
/// assert!(!net.contains(ip2));
|
||||||
/// assert!(!net.contains(ip4));
|
/// assert!(!net.contains(ip4));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
pub fn contains(&self, ip: IpAddr) -> bool {
|
pub fn contains(&self, ip: IpAddr) -> bool {
|
||||||
match (*self, ip) {
|
match (*self, ip) {
|
||||||
(IpNetwork::V4(net), IpAddr::V4(ip)) => net.contains(ip),
|
(IpNetwork::V4(net), IpAddr::V4(ip)) => net.contains(ip),
|
||||||
|
Reference in New Issue
Block a user