mogwai icon indicating copy to clipboard operation
mogwai copied to clipboard

Use `NonZeroUsize` rather than `usize` to prevent panic scenario

Open mx00s opened this issue 3 years ago • 2 comments

A NonZeroUsize parameter instead of a usizeto specify the capacity of a bounded channel would eliminate the panic scenario.

mx00s avatar Dec 27 '21 18:12 mx00s

Hey! Great idea.

schell avatar Dec 31 '21 03:12 schell

It might take me a bit to get to this, I'm currently on holiday. If you're feeling antsy I would definitely accept a pull request.

schell avatar Dec 31 '21 03:12 schell

I tried this out and although it is more correct to use a NonZeroUsize for the capacity, it is quite inconvenient. I also found that I just ended up calling 1.try_into().unwrap() while creating all of my channels and while this is more explicit (which I like) it was a pain. I temporarily included a constant const ONE: NonZeroUsize = ... but ultimately decided not to include this change in 0.6.

I might pick it back up for 0.7, but I might also just remove the channels in favor of Input, FanInput and Output.

schell avatar Jan 07 '23 07:01 schell