Skip to content

Commit 43b7a74

Browse files
authored
Add direct conversion from SockAddrIn(6) to SocketAddr (#2474)
1 parent 62ad90a commit 43b7a74

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

changelog/2474.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `From` trait implementation between `SocketAddr` and `Sockaddr`, `Sockaddr6`

src/sys/socket/addr.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,13 @@ impl From<SockaddrIn> for net::SocketAddrV4 {
919919
}
920920
}
921921

922+
#[cfg(feature = "net")]
923+
impl From<SockaddrIn> for net::SocketAddr {
924+
fn from(addr: SockaddrIn) -> Self {
925+
net::SocketAddr::from(net::SocketAddrV4::from(addr))
926+
}
927+
}
928+
922929
#[cfg(feature = "net")]
923930
impl From<SockaddrIn> for libc::sockaddr_in {
924931
fn from(sin: SockaddrIn) -> libc::sockaddr_in {
@@ -1075,6 +1082,13 @@ impl From<SockaddrIn6> for net::SocketAddrV6 {
10751082
}
10761083
}
10771084

1085+
#[cfg(feature = "net")]
1086+
impl From<SockaddrIn6> for net::SocketAddr {
1087+
fn from(addr: SockaddrIn6) -> Self {
1088+
net::SocketAddr::from(net::SocketAddrV6::from(addr))
1089+
}
1090+
}
1091+
10781092
#[cfg(feature = "net")]
10791093
impl std::str::FromStr for SockaddrIn6 {
10801094
type Err = net::AddrParseError;

0 commit comments

Comments
 (0)