-
Notifications
You must be signed in to change notification settings - Fork 592
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
Event type #1053
Event type #1053
Conversation
The error on beta and nightly is very similar to the compilation error I was getting. Has that been seen before? |
No. The lifetime you added is also wrong. The |
Will do, I'll push a diff in a second. One question, would you prefer that event names, since they appear in multiple places, be factored into constants? I.e. |
Sure. |
Add `Event::event_type` method that returns the type of the event.
This returns this original event name, in screaming snake case, as originally returned by the Discord API. `GuildUnavailable` is a synthetic event type, corresponding to either `GUILD_CREATE` or `GUILD_DELETE`, but we don't have enough information to recover the name here, so this function returns `None` if called on `GuildUnavailable`.
Done, I removed the lifetime and refactored event name strings into constants. I'm not getting the compilation error anymore, so it must have been something wrong on my end. |
I believe that currently, it is only possible to omit the static lifetime for normal constants, not associated constants. (See this issue.) As an alternative, I could make them not associate constants, i.e. move them out of |
That's a pity. I thought that works for associated constansts as well, but it's apparently intentional that it doesn't. You can ignore my change, your pull request is fine as is. I'll merge it later. And once I also investigate the error, it is happening in CI again, this time just for the framework example... |
I think we may have a case of a heisenbug tormenting us. I've tried testing from my copy of serenity, your copy of serenity, switching between the stable, beta, and nightly toolchains, yet I am unable to consistently reproduce the error. I also just tried restarting all of the CI jobs and the error has disappeared. Well, I guess I have the liberty to merge your pull request, but the error is strange nonetheless. |
Very weird! I know I saw it locally a few times, so it must not be CI-specific. Thank you for reviewing! |
This adds a method to get the
EventType
of anEvent
. I needed this for logging and statistics. Hopefully it's useful to others!For some reason I was getting compilation failures, but adding the lifetime fixed them.
I also added
EventType::name
, which returns the screaming-snake-case name as originally returned by the API. This doesn't apply cleanly on its own, so I included it in this PR, since it's related.