mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-16 00:48:10 +00:00
Merge pull request #41 from faern/impl-display
Implement Display for IpNetwork
This commit is contained in:
10
src/lib.rs
10
src/lib.rs
@ -5,6 +5,7 @@
|
||||
#![cfg_attr(feature = "dev", plugin(clippy))]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
use std::fmt;
|
||||
use std::net::IpAddr;
|
||||
|
||||
mod ipv4;
|
||||
@ -158,6 +159,15 @@ impl From<Ipv6Network> for IpNetwork {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for IpNetwork {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
IpNetwork::V4(net) => net.fmt(f),
|
||||
IpNetwork::V6(net) => net.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a `IpAddr` network mask into a prefix.
|
||||
/// If the mask is invalid this will return an `IpNetworkError::InvalidPrefix`.
|
||||
pub fn ip_mask_to_prefix(mask: IpAddr) -> Result<u8, IpNetworkError> {
|
||||
|
Reference in New Issue
Block a user