diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index f5348934310e8..d186a53311dab 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -760,6 +760,14 @@ impl<'a, T: ToSocketAddrs + ?Sized> ToSocketAddrs for &'a T { } } +#[stable(feature = "string_to_socket_addrs", since = "1.16.0")] +impl ToSocketAddrs for String { + type Iter = vec::IntoIter; + fn to_socket_addrs(&self) -> io::Result> { + (&**self).to_socket_addrs() + } +} + #[cfg(all(test, not(target_os = "emscripten")))] mod tests { use net::*; @@ -797,6 +805,18 @@ mod tests { assert!(tsa("localhost:23924").unwrap().contains(&a)); } + #[test] + fn to_socket_addr_string() { + let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 24352); + assert_eq!(Ok(vec![a]), tsa(&*format!("{}:{}", "77.88.21.11", "24352"))); + assert_eq!(Ok(vec![a]), tsa(&format!("{}:{}", "77.88.21.11", "24352"))); + assert_eq!(Ok(vec![a]), tsa(format!("{}:{}", "77.88.21.11", "24352"))); + + let s = format!("{}:{}", "77.88.21.11", "24352"); + assert_eq!(Ok(vec![a]), tsa(s)); + // s has been moved into the tsa call + } + // FIXME: figure out why this fails on openbsd and bitrig and fix it #[test] #[cfg(not(any(windows, target_os = "openbsd", target_os = "bitrig")))]