Skip to content

Commit

Permalink
Add direct conversion from SockAddrIn(6) to SocketAddr (#2474)
Browse files Browse the repository at this point in the history
  • Loading branch information
pronebird authored Aug 23, 2024
1 parent 62ad90a commit 43b7a74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/2474.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `From` trait implementation between `SocketAddr` and `Sockaddr`, `Sockaddr6`
14 changes: 14 additions & 0 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,13 @@ impl From<SockaddrIn> for net::SocketAddrV4 {
}
}

#[cfg(feature = "net")]
impl From<SockaddrIn> for net::SocketAddr {
fn from(addr: SockaddrIn) -> Self {
net::SocketAddr::from(net::SocketAddrV4::from(addr))
}
}

#[cfg(feature = "net")]
impl From<SockaddrIn> for libc::sockaddr_in {
fn from(sin: SockaddrIn) -> libc::sockaddr_in {
Expand Down Expand Up @@ -1075,6 +1082,13 @@ impl From<SockaddrIn6> for net::SocketAddrV6 {
}
}

#[cfg(feature = "net")]
impl From<SockaddrIn6> for net::SocketAddr {
fn from(addr: SockaddrIn6) -> Self {
net::SocketAddr::from(net::SocketAddrV6::from(addr))
}
}

#[cfg(feature = "net")]
impl std::str::FromStr for SockaddrIn6 {
type Err = net::AddrParseError;
Expand Down

0 comments on commit 43b7a74

Please sign in to comment.