-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Add a builder for CallbackData #1146
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.
Also on all methods, separate the assignment self.field = Some(value);
and returning self
with a blank line.
@vilgotf I resolved your review comments |
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.
Last thing: add an assert_impl_all!
and verify Debug, Default, Send, Sync
self._content(content.into()) | ||
} | ||
|
||
#[allow(clippy::missing_const_for_fn)] |
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.
Is there a reason this isn't const?
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.
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.
Even if this was const, wouldn't it not matter as content
itself can't be const?
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 think this is blocking on #1056 tho
This can now be updated, please put the builder in the |
736cdba
to
9740a3a
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.
thanks for the changes, a few things:
util/src/builder/callback_data.rs
Outdated
/// # Example | ||
/// ``` | ||
/// use twilight_util::builder::CallbackDataBuilder; | ||
/// use twilight_model::channel::message::MessageFlags; | ||
/// | ||
/// let callback_data = CallbackDataBuilder::new() | ||
/// .content("My callback message") | ||
/// .flags(MessageFlags::EPHEMERAL) | ||
/// .build(); | ||
/// ``` |
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.
Can we move this example to a module-level doc comment?
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.
Do you want to move it to the builder
module documentation? As the callback_data
module contains only one struct, I thought that re-exporting the type directly to the root of the builder
and making callback_data
module private was better.
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 mean in the same file, just having it at the top with //!
comments. See cache/in-memory/src/permission.rs
for an example
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.
Which appears like this: https://api.twilight.rs/twilight_cache_inmemory/permission/index.html
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.
Yes, but actually the util::builder::callback_data
is not exported, only the CallbackDataBuilder
type is re-exported in the builder
module. Do you want to export the callback_data
module entirely?
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'll have to get back to you on this, I'll pull in the code and play around with how it renders, then let you know.
Co-authored-by: Cassandra McCarthy <cassie@7596ff.com>
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.
These are all just documentation nits.
I've played around with it. I think for this builder and the command builder, I feel it would be best to respect the |
Co-authored-by: Cassandra McCarthy <cassie@7596ff.com>
I think that naming the type "Best practices" enforced by Clippy are great to ensure an overall quality of the code, but should not make code harder to understand by developers using the library. It's why I think exporting builders at the root of the crate is actually the best option to make them easily discoverable, as we can have at a glance an overview of all available builders. Furthermore, I think that it could be great to introduce a feature in the |
After referring back to #1056, I realize my proposal conflicts with the other proposed design, so we'll just scrap it. I also agree with your first two paragraphs, so thank you for writing them.
As for discoverability, we are actually meant to link to the builders on their respective types 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.
Could you also alphabetize the methods of CallbackDataBuilder
& add components
to the example?
Co-authored-by: Vilgot Fredenberg <vilgot@fredenberg.xyz>
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.
sorry, the methods were already good 😅, could you revert that change?
- new
- build
- (rest of the methods in alphabetical order)
No problem, changes reverted. (oops I wrote half of the commit message in French) |
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.
Clippy error is irrelevant
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.
one more thing
This PR adds a builder for [`CallbackData`](https://docs.rs/twilight-model/0.6.2/twilight_model/application/callback/struct.CallbackData.html). Similar design to the other builders in the `model` crate. I needed to add some `#[allow(clippy::missing_const_for_fn)]` to ignore Clippy false positives. Closes twilight-rs#976. Co-authored-by: Cassandra McCarthy <cassie@7596ff.com> Co-authored-by: Vilgot Fredenberg <vilgot@fredenberg.xyz>
Adds the `builder` module, which is currently populated with the `CommandBuilder` ([#1048] - [@vilgotf]) and the `CallbackDataBuilder` ([#1146] - [@baptiste0928]). [#1048]: #1048 [#1146]: #1146 [@baptiste0928]: https://github.com/baptiste0928 [@vilgotf]: https://github.com/vilgotf
This PR adds a builder for
CallbackData
. Similar design to the other builders in themodel
crate. I needed to add some#[allow(clippy::missing_const_for_fn)]
to ignore Clippy false positives.Closes #976