Implement Display for IpNetwork

This commit is contained in:
Linus Färnstrand
2017-04-02 15:19:48 +02:00
parent 6980958412
commit f61db46006

View File

@ -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> {