-
Notifications
You must be signed in to change notification settings - Fork 597
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
Improve tokens semantics and clean up gateway feature gates #3052
Conversation
c4b13f2
to
0bccd4c
Compare
0bccd4c
to
5de6e13
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.
This looks mainly good just some minor issues:
- Can you add a
Token::from_env("DISCORD_TOKEN")
helper for the examples? - Can you remove the
Http::default
implementation, and haveHttp::new
take the token with aHttp::wthout_token
constructor for webhook-only use, since this is the super minority of use cases.
Done. |
8277ca4
to
e62f1aa
Compare
/// An error from the [`secrets`] module. | ||
/// | ||
/// [`secrets`]: crate::secrets | ||
Token(TokenError), |
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.
Does this have to be a part of this enum? I can't see a spot that returns this instead of just Result<T, TokenError>
.
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 figured this would be useful when using ?
so that TokenError
could coerce to Error
.
This divorces the gateway feature from the model/http code such that there is no cross-contamination (setting the stage for a crate split). A few doctests got rewritten to not rely on the gateway, and the
Http::token
method was removed. The gateway structs now carry their own copy of the token, and the Http token field was made optional for users who only care about webhooks.Furthermore, renamed the
secret_string
module tosecrets
and added aToken
type that can partially validate token strings. This type is what is now passed in to the client. The user is expected to call eitherstr::parse::<Token>()
orToken::from_str
in order to create a Client.