Auto merge of #31161 - sfackler:slice-to-socket-addrs, r=alexcrichton

This is useful when you have an API that takes a `T: ToSocketAddrs` and needs to turn that into an owned value which will be passed to another API taking `T: ToSocketAddrs` at a later time, for example: https://github.com/sfackler/rust-hyper-socks/blob/master/src/lib.rs#L15
This commit is contained in:
bors 2016-02-04 13:41:42 +00:00
commit e64ca8cd59

View File

@ -21,6 +21,8 @@ use option;
use sys::net::netc as c;
use sys_common::{FromInner, AsInner, IntoInner};
use vec;
use iter;
use slice;
/// Representation of a socket address for networking applications.
///
@ -457,6 +459,15 @@ impl ToSocketAddrs for str {
}
}
#[stable(feature = "slice_to_socket_addrs", since = "1.8.0")]
impl<'a> ToSocketAddrs for &'a [SocketAddr] {
type Iter = iter::Cloned<slice::Iter<'a, SocketAddr>>;
fn to_socket_addrs(&self) -> io::Result<Self::Iter> {
Ok(self.iter().cloned())
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T: ToSocketAddrs + ?Sized> ToSocketAddrs for &'a T {
type Iter = T::Iter;