I'm teaching myself some Rust by writing a WebSocket client application. The app is continuously processing messages, but sometimes I want to pause the processing. While on pause I want to buffer incoming messages. Then once the app is resumed the buffered messages will be processed in order. I managed to build this solution:
Could you please make code review on this? Maybe I should rewrite this using different approach/types?
The strange thing about ProcessBuffer is that it takes a reference to a message, and then clones it. Unless for some reason the incoming messages are delivered by reference (in which case accepting the reference saves cloning all non-buffered messages) you should take and return the messages by value. Then you don’t need the clone(), the T: Clone bound, the to_discard field and code, or any lifetime annotations.