From f61db46006518b2b958657db57e5b5facd89b13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 2 Apr 2017 15:19:48 +0200 Subject: [PATCH] Implement Display for IpNetwork --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 64def08..0a09254 100644 --- a/src/lib.rs +++ b/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 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 {