Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API parameters that are asserted to be non-zero should be of type NonZeroUsize or similar. #2742

Closed
khuey opened this issue Aug 7, 2020 · 4 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync

Comments

@khuey
Copy link

khuey commented Aug 7, 2020

A number of parameters in various tokio APIs are usizes that must be non-zero, e.g. core_threads, max_threads, the argument to mpsc::channel, etc. The last one tripped me up when porting code because crossbeam::mpsc::channel(0) is equivalent to tokio::mpsc::channel(1). This can all be enforced in the type system and be caught at compile time.

@khuey khuey added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Aug 7, 2020
@Darksonn Darksonn added M-sync Module: tokio/sync C-feature-request Category: A feature request. and removed C-bug Category: This is a bug. labels Aug 7, 2020
@taiki-e
Copy link
Member

taiki-e commented Oct 5, 2020

@khuey
Copy link
Author

khuey commented Oct 10, 2020

Seems that something like rust-lang/rust#69329 would be helpful here then.

@carllerche
Copy link
Member

NonZeroUsize isn't really intended for APIs. It is intended to help the compiler optimize struct layout. It also is not idiomatic Rust.

@Lucretiel
Copy link

It also is not idiomatic Rust.

It's not? I've been more and more using it for this exact purpose, what's wrong with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync
Projects
None yet
Development

No branches or pull requests

5 participants