diff --git a/src/util.rs b/src/util.rs
index 86e3f0c..f29b262 100644
@@ -17,7 +17,7 @@ use std::fmt;
use std::str::{FromStr, from_utf8_unchecked};
use std::mem;
use std::u8;
-use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
+use std::net::{Ipv4Addr, Ipv6Addr};
#[cfg(not(windows))]
@@ -135,6 +135,23 @@ pub enum IpAddr {
V6(Ipv6Addr)
}
+impl FromStr for IpAddr {
+ type Err = ();
+ fn from_str(s: &str) -> Result<IpAddr, ()> {
+ let ipv4: Result<Ipv4Addr, _> = FromStr::from_str(s);
+ let ipv6: Result<Ipv6Addr, _> = FromStr::from_str(s);
+ match ipv4 {
+ Ok(res) => Ok(IpAddr::V4(res)),
+ Err(_) => {
+ match ipv6 {
+ Ok(res) => Ok(IpAddr::V6(res)),
+ Err(_) => Err(()),
+ }
+ },
+ }
+ }
+}
+
impl fmt::Debug for IpAddr {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, fmt)