Skip to content

Commit 1df9fb5

Browse files
committed
Improve ergonomics between SockaddrIn and underlying libc type
1 parent 7badbee commit 1df9fb5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

changelog/2328.added.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add `Into<sockaddr_in>` for `SockaddrIn`
2+
- Add `Into<sockaddr_in6>` for `SockaddrIn6`

src/sys/socket/addr.rs

+16
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,15 @@ impl From<SockaddrIn> for net::SocketAddrV4 {
920920
}
921921

922922
#[cfg(feature = "net")]
923+
#[allow(clippy::from_over_into)]
924+
impl Into<libc::sockaddr_in> for SockaddrIn {
925+
fn into(self) -> libc::sockaddr_in {
926+
self.0
927+
}
928+
}
929+
930+
#[cfg(feature = "net")]
931+
#[allow(clippy::from_over_into)]
923932
impl std::str::FromStr for SockaddrIn {
924933
type Err = net::AddrParseError;
925934

@@ -969,6 +978,13 @@ impl SockaddrIn6 {
969978
}
970979
}
971980

981+
#[cfg(feature = "net")]
982+
impl Into<libc::sockaddr_in6> for SockaddrIn6 {
983+
fn into(self) -> libc::sockaddr_in6 {
984+
self.0
985+
}
986+
}
987+
972988
#[cfg(feature = "net")]
973989
impl private::SockaddrLikePriv for SockaddrIn6 {}
974990
#[cfg(feature = "net")]

0 commit comments

Comments
 (0)