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
@joshtriplett
Copy link
Copy Markdown
Member

@bors try @craterbot check

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 5, 2026
…=<try>

experiment: Support NonZero<u16> in ToSocketAddr impls
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 5, 2026

☀️ Try build successful (CI)
Build commit: 265c011 (265c011446066911606f67974ba9239b86ef0f62, parent: 4feb7221f4d445120a5061b16ce7222adbfdf6f6)

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.

4 participants