Skip to content

Commit e64ca8c

Browse files
committed
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
2 parents 7b9d6d3 + 7ea0abf commit e64ca8c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/net/addr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use option;
2121
use sys::net::netc as c;
2222
use sys_common::{FromInner, AsInner, IntoInner};
2323
use vec;
24+
use iter;
25+
use slice;
2426

2527
/// Representation of a socket address for networking applications.
2628
///
@@ -457,6 +459,15 @@ impl ToSocketAddrs for str {
457459
}
458460
}
459461

462+
#[stable(feature = "slice_to_socket_addrs", since = "1.8.0")]
463+
impl<'a> ToSocketAddrs for &'a [SocketAddr] {
464+
type Iter = iter::Cloned<slice::Iter<'a, SocketAddr>>;
465+
466+
fn to_socket_addrs(&self) -> io::Result<Self::Iter> {
467+
Ok(self.iter().cloned())
468+
}
469+
}
470+
460471
#[stable(feature = "rust1", since = "1.0.0")]
461472
impl<'a, T: ToSocketAddrs + ?Sized> ToSocketAddrs for &'a T {
462473
type Iter = T::Iter;

0 commit comments

Comments
 (0)