Merge pull request #41 from faern/impl-display

Implement Display for IpNetwork
This commit is contained in:
Abhishek Chanda
2017-04-02 16:47:48 +01:00
committed by GitHub

View File

@ -5,6 +5,7 @@
#![cfg_attr(feature = "dev", plugin(clippy))] #![cfg_attr(feature = "dev", plugin(clippy))]
#![crate_type = "lib"] #![crate_type = "lib"]
use std::fmt;
use std::net::IpAddr; use std::net::IpAddr;
mod ipv4; 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. /// Converts a `IpAddr` network mask into a prefix.
/// If the mask is invalid this will return an `IpNetworkError::InvalidPrefix`. /// If the mask is invalid this will return an `IpNetworkError::InvalidPrefix`.
pub fn ip_mask_to_prefix(mask: IpAddr) -> Result<u8, IpNetworkError> { pub fn ip_mask_to_prefix(mask: IpAddr) -> Result<u8, IpNetworkError> {