polyphony-chat / chorus

A rust library for interacting with multiple Spacebar-compatible Instances at once.
https://crates.io/crates/chorus
Mozilla Public License 2.0
16 stars 7 forks source link

Derive for `impl WebSocketEvent for ... {}` #486

Closed bitfl0wer closed 2 months ago

bitfl0wer commented 3 months ago

In chorus, every event which is also a WebSocketEvent needs to implement the WebSocketEvent trait. The WebSocketEvent trait is a marker trait, which means it has no methods or associated types. It is used to group all events that can be sent over a WebSocket connection.

Currently, the WebSocketEvent marker trait gets implemented as such

impl WebSocketEvent for Event1 {}

This is a bit cumbersome, as it requires us to manually implement the trait for every event. It would be nice if we could add a derive macro to automatically implement the trait for us.

#[derive(WebSocketEvent)]
struct Event1;