Improve ergonomics between SockaddrIn and underlying libc type #2328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do
Checklist:
I have read
CONTRIBUTING.md
I have written necessary tests and rustdoc comments
A change log has been added if this PR modifies nix's API
Add
Into<libc::sockaddr_in6> for SockaddrIn6
Add
Into<libc::sockaddr_in> for SockaddrIn
My typical use case for these
Into
traits is when I am bridging from safe world into the world of pain (C). For example, presently I have to go overas_ref()
to access the underlyingsockaddr_inX
. This is a bit verbose for my liking, so I figured it would be great to haveinto()
to do the job for me. UsuallyFrom
is preferred but I am not certain if we want that, hence I have implementedInto
but can easily flip toFrom
if that makes sense.I also noticed that
repr(transparent)
is set on these structs and naturally I thought I could useaddr_sa as sockaddr_in6
but that doesn't seem to compile.