Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl EventHandler for Vec<Box<EventHandler>> #424

Closed
wants to merge 2 commits into from

Conversation

fenhl
Copy link
Contributor

@fenhl fenhl commented Oct 30, 2018

This PR adds an implementation of EventHandler for Vec<Box<EventHandler>>, which allows splitting up handler code into multiple types implementing the trait. For example, I have multiple bots that serialize voice state to disk, this would allow me to reuse the same code for these and still have specific event handler code for each bot.

The implementation is generated using a macro, so that new trait methods of EventHandler are automatically implemented correctly when added.

@arqunis arqunis added the enhancement An improvement to Serenity. label Oct 30, 2018
@arqunis
Copy link
Member

arqunis commented Oct 31, 2018

Could you add an example in the examples folder? Would make the intention of this impl clearer.

@arqunis
Copy link
Member

arqunis commented Dec 22, 2018

The implementation is made possible by .clone()-ing the arguments to each subsequent event handler.
However, this is bad as it can cause memory/performance inflation for events that are dispatched by discord rapidly (e.g PRESENCE_UPDATE). So, until the cloning can be bypassed or a better solution is discovered, I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement to Serenity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants