feat(cache,http,model)!: add AfkTimeout for Guild::afk_timeout#1922
Merged
feat(cache,http,model)!: add AfkTimeout for Guild::afk_timeout#1922
AfkTimeout for Guild::afk_timeout#1922Conversation
AfkTimeout for Guild::afk_timeoutAfkTimeout for Guild::afk_timeout
7596ff
previously requested changes
Sep 16, 2022
vilgotf
reviewed
Sep 22, 2022
Member
vilgotf
left a comment
There was a problem hiding this comment.
How about using associated consts and a newtype?
pub struct AfkTimeout(u16);
impl AfkTimeout {
pub const ONE_MINUTE: Self = Self(60);
// etc
}Rework AFK timeouts from being a simple integer to a newtype with associated constants for valid values and parsing into `std::time::Duration`s. BREAKING CHANGES: `Guild::afk_timeout` and similar are now `twilight_model::guild::AfkTimeout` instead of an integer.
30299c5 to
f86a3a7
Compare
AfkTimeout for Guild::afk_timeoutAfkTimeout for Guild::afk_timeout
7596ff
approved these changes
Dec 29, 2022
vilgotf
approved these changes
Dec 29, 2022
Member
vilgotf
left a comment
There was a problem hiding this comment.
Using associated consts looks slick!
Comment on lines
+51
to
+55
| impl From<u16> for AfkTimeout { | ||
| fn from(value: u16) -> Self { | ||
| Self(value) | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Just highlighting that this allows any value
Member
There was a problem hiding this comment.
I think this is fine since it's non exaustive and we have no guarantee discord won't add any extra values later
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AFK timeout of a guild has been represented as an integer, despite the fact that the AFK timeout of a guild can only be a select list of integers rather than a freeform value. To achieve a nice UX while maintaining the representation of an integer, a newtype over an integer with associated constants for known valid values has been introduced.
Example:
Reference: #1904
Closes: #1904