Use NonZeroUsize instead of panicking on zero
opened this issue · comments
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.
Related: rust-lang/futures-rs#1803
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()
.