Skip to content

experiment: Support NonZero<u16> in ToSocketAddr impls#155983

Draft
edward-shen wants to merge 1 commit intorust-lang:mainfrom
edward-shen:edward-shen/nonzero-port-impls
Draft

experiment: Support NonZero<u16> in ToSocketAddr impls#155983
edward-shen wants to merge 1 commit intorust-lang:mainfrom
edward-shen:edward-shen/nonzero-port-impls

Conversation

@edward-shen
Copy link
Copy Markdown
Contributor

This is a draft PR for a crater run requested in rust-lang/libs-team#781.


All tuple From implementations for ToSocketAddr currently only accept a u16 as the port number. This results in a small ergonomics penalty for users that parse out a NonZero port number from the program's arguments.

This adds a small set of implementations that copies any tuple implementation on ToSocketAddr that takes in a u16 as a port and instead accepts a NonZero<u16>.

For consistency, a From<(I, NonZeroU16)> implementation for SocketAddr was also implemented.

As far as I can tell, these implementations will be insta-stable.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 30, 2026
@edward-shen
Copy link
Copy Markdown
Contributor Author

@bors try

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 30, 2026

@edward-shen: 🔑 Insufficient privileges: not in try users

@rust-log-analyzer

This comment has been minimized.

All tuple From implementations for ToSocketAddr currently only accept
a u16 as the port number. This results in a small ergonomics penalty
for users that parse out a NonZero port number from the program's
arguments.

This adds a small set of implementations that copies any tuple
implementation on ToSocketAddr that takes in a u16 as a port and instead
accepts a NonZero<u16>.

For consistency, a From<(I, NonZeroU16)> implementation for SocketAddr
was also implemented.
@edward-shen edward-shen force-pushed the edward-shen/nonzero-port-impls branch from e8a90dd to 00f08d0 Compare April 30, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants