-
-
Notifications
You must be signed in to change notification settings - Fork 139
feat(model): initial pass at dealing with unknown enum variants #1550
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some basic formatting, probably missed a lot.
Thanks, for the formatting i'm aware there is probably a lot more that needs fixing. i chose to not fix them yet for this draft because the design of this isn't fully done yet, and i'm currently looking for feedback on how it should look/work in the end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only commented on things once and didn't comment on formatting. Do we still have uses of the serde_repr
dependency after this?
We don't really need to test the tokens, we're essentially testing serde at that point. We should test our own conversion implementations.
I believe we're in the long-term process of separating types between their incoming and outgoing variants. I am in favor of more flattening in general but I don't believe it's in the scope of this PR.
I think if people want to use cutting edge new API features that we don't support they can use manual HTTP request bodies. Type flattening may also aid in this, but again out of scope. We may need to place some sort of priority on investigating the role flattening would have for us in general. |
Yes, several gateway and interaction structs still use these.
i'll replace the relevant tests with just testing the conversions without serde then
Agreed, i think we can live with it being not perfect here in what data we give when it's unknown and then clean up these few last spots when things are flattened |
88f8027
to
a258354
Compare
This does need further work, and based on some discussion in Discord, there seems to be a path forward. We should bracket any work on unknown interaction variants for now, in order to solve that problem more correctly at a later date. Also, we should try to build on whatever existing tests there are for the affected types, and follow up later to make them more consistent with each other and more correct. Lastly, I'll be making a quick PR to add the Forum channel type, as a stopgap in a minor release, which will come before a) this PR and b) Erk's work on the entire forum feature later on. |
As a stopgap before future work on Forum channels, add their channel type in order to stop deserialization errors which would be more correctly fixed in #1550.
As a stopgap before future work on Forum channels, add their channel type in order to stop deserialization errors which would be more correctly fixed in #1550.
a258354
to
882c585
Compare
882c585
to
5230695
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, a bunch of small consistency nits
Co-authored-by: Cassandra McCarthy <[email protected]>
a258354
to
3e162cd
Compare
@@ -52,6 +78,7 @@ impl ComponentType { | |||
Self::Button => "Button", | |||
Self::SelectMenu => "SelectMenu", | |||
Self::TextInput => "TextInput", | |||
Self::Unknown(_) => "Unknown", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Commenting on this one, applis on all).
I'm not sure I like the display implementation being "Unknown", should be the number imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually isn't possible unless i'm missing something. These functions return an &'static str
. Converting the number to a string would yield a string that is owned in this scope only and thus can not be returned out of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's impossible in this method, but I meant for the Display
implementation; currently it just calls this method, it would be better to print the integer (+ Unknown
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't have a display implementation for most of these, this looks like the only one that has it. It also would require to duplicate the entire match. It seems better to keep this consistent here, and look at if they should all have display implementations (or if this one should be removed) separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's as simple as:
fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
if let Unknown(int) = self {
Display::fmt(&int, f)
} else {
f.write_str(self.name())
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't have a display implementation for most of these, this looks like the only one that has it.
Ah I missed this, maybe it should be removed at a later point then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of moving to a Display
implementation later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it as is for now then to not scope creep this PR, and follow it up to move to display soon after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Excited for this change and what it makes possible.
Looks good, should we mention in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for the effort on it! With a rebase is this good to go?
Reworking enums to have unknown variants to handle discord adding new api features.
Goal: not losing any payloads whenever discord adds something new, while keeping the type safety the enums provide since people depend on that.
This is an initial WIP draft to get discussion going on how the final implementation should look, but is fully functional.
Left to do on this:
standardize serialization and deserialization tests. they where all over the place, some check serde tokens, others just conversions without serde. We need to decide what kind of test general model serializations and deserializations should have=> best left for a seperate PR