smol-rs / async-channel

Async multi-producer multi-consumer channel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

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().