schell / mogwai

The minimalist, obvious, graphical, web application interface
429 stars 26 forks source link

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

Closed mx00s closed 1 year ago

mx00s commented 2 years ago

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

schell commented 2 years ago

Hey! Great idea.

schell commented 2 years ago

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 commented 1 year ago

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.