Skip to content

Commit

Permalink
Improve ergonomics between SockaddrIn and underlying libc type
Browse files Browse the repository at this point in the history
  • Loading branch information
pronebird committed Mar 6, 2024
1 parent 7badbee commit 2c74fa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog/2328.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `Into<sockaddr_in>` for `SockaddrIn`
- Add `Into<sockaddr_in6>` for `SockaddrIn6`
16 changes: 16 additions & 0 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,15 @@ impl From<SockaddrIn> for net::SocketAddrV4 {
}

#[cfg(feature = "net")]
#[allow(clippy::from-over-into)]
impl Into<libc::sockaddr_in> for SockaddrIn {
fn into(self) -> libc::sockaddr_in {
self.0
}
}

#[cfg(feature = "net")]
#[allow(clippy::from-over-into)]
impl std::str::FromStr for SockaddrIn {
type Err = net::AddrParseError;

Expand Down Expand Up @@ -969,6 +978,13 @@ impl SockaddrIn6 {
}
}

#[cfg(feature = "net")]
impl Into<libc::sockaddr_in6> for SockaddrIn6 {
fn into(self) -> libc::sockaddr_in6 {
self.0
}
}

#[cfg(feature = "net")]
impl private::SockaddrLikePriv for SockaddrIn6 {}
#[cfg(feature = "net")]
Expand Down

0 comments on commit 2c74fa0

Please sign in to comment.