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

Use NonZeroUsize instead of panicking on zero #2

Closed
ghost opened this issue Jun 9, 2020 · 2 comments
Closed

Use NonZeroUsize instead of panicking on zero #2

ghost opened this issue Jun 9, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 9, 2020

The documentation states:

Capacity must be a positive number. If cap is zero, this function will panic.

This could be fixed by taking a NonZeroUsize instead.

@taiki-e
Copy link
Collaborator

taiki-e commented Jun 9, 2020

Related: rust-lang/futures-rs#1803

@ghost
Copy link

ghost commented Jun 9, 2020

This would make the API more cumbersome to use without helping much:

let (s, r) = async_channel::bounded(NonZeroUsize::new(n).unwrap());

We still need to either do .unwrap() to panic or do something else to handle the case when n is zero. However, I imagine in nearly 100% cases people would just do .unwrap().

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant