mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-16 16:58:50 +00:00
Merge pull request #28 from achanda/ipnetwork_mask
Implement mask for IpNetwork
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@ -2,7 +2,6 @@
|
|||||||
#![cfg_attr(feature = "dev", feature(plugin))]
|
#![cfg_attr(feature = "dev", feature(plugin))]
|
||||||
#![cfg_attr(feature = "dev", plugin(clippy))]
|
#![cfg_attr(feature = "dev", plugin(clippy))]
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#[allow(dead_code)]
|
|
||||||
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
@ -65,6 +64,22 @@ impl IpNetwork {
|
|||||||
IpNetwork::V6(ref a) => a.prefix(),
|
IpNetwork::V6(ref a) => a.prefix(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the mask of the given `IpNetwork`
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use ipnetwork::IpNetwork;
|
||||||
|
///
|
||||||
|
/// assert_eq!(IpNetwork::V4("10.9.0.32/16".parse().unwrap()).mask(), 16u8);
|
||||||
|
/// assert_eq!(IpNetwork::V6("ff01::0/32".parse().unwrap()).mask(), 32u8);
|
||||||
|
///```
|
||||||
|
pub fn mask(&self) -> IpAddr {
|
||||||
|
match *self {
|
||||||
|
IpNetwork::V4(ref a) => IpAddr::V4(a.mask()),
|
||||||
|
IpNetwork::V6(ref a) => IpAddr::V6(a.mask()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a `IpAddr` network mask into a prefix.
|
/// Converts a `IpAddr` network mask into a prefix.
|
||||||
|
Reference in New Issue
Block a user