Skip to content
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

Merged
merged 13 commits into from
Oct 2, 2021

Conversation

baptiste0928
Copy link
Member

This PR adds a builder for CallbackData. 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 #976

model/src/application/callback/callback_data.rs Outdated Show resolved Hide resolved
model/src/application/callback/callback_data.rs Outdated Show resolved Hide resolved
model/src/application/callback/callback_data.rs Outdated Show resolved Hide resolved
Copy link
Member

@vilgotf vilgotf left a 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.

@baptiste0928
Copy link
Member Author

@vilgotf I resolved your review comments

Copy link
Member

@vilgotf vilgotf left a 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)]
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compilation fails if the function is const. I don't know much about const fns, maybe there is a way to fix it properly.

image

Copy link
Contributor

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?

vilgotf
vilgotf previously approved these changes Sep 2, 2021
Copy link
Member

@vilgotf vilgotf left a 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

@zeylahellyer zeylahellyer added c-model Affects the model crate t-feature Addition of a new feature f-application-commands labels Sep 5, 2021
@zeylahellyer zeylahellyer marked this pull request as draft September 5, 2021 16:02
@7596ff
Copy link
Contributor

7596ff commented Sep 30, 2021

This can now be updated, please put the builder in the util/builder module.

@baptiste0928 baptiste0928 marked this pull request as ready for review September 30, 2021 18:44
Copy link
Contributor

@7596ff 7596ff left a 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/lib.rs Show resolved Hide resolved
util/src/builder/mod.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
Comment on lines 11 to 20
/// # 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();
/// ```
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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?

Copy link
Contributor

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>
7596ff
7596ff previously requested changes Oct 1, 2021
Copy link
Contributor

@7596ff 7596ff left a 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.

util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
@7596ff
Copy link
Contributor

7596ff commented Oct 1, 2021

I've played around with it. I think for this builder and the command builder, I feel it would be best to respect the clippy::module_name_repetitions lint, name the primary builder of the module Builder, and allow users to rename it on import. This should be discussed though. What do y'all think?

Co-authored-by: Cassandra McCarthy <cassie@7596ff.com>
@baptiste0928
Copy link
Member Author

I think that naming the type Builder will be confusing for most users. This will also make it harder to discover builders, as the search bar will become less relevant, and it will not be clear whether a builder is available for a given 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 model crate to add builder() methods on types that provide a builder. This will at least show that a builder is available in docs.rs, and will make them easier to discover.

@7596ff
Copy link
Contributor

7596ff commented Oct 1, 2021

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.

Furthermore, I think that it could be great to introduce a feature in the model crate to add builder() methods on types that provide a builder. This will at least show that a builder is available in docs.rs, and will make them easier to discover.

As for discoverability, we are actually meant to link to the builders on their respective types in model, so I'd like it if we did that instead of making a new feature on model at this time.

Copy link
Member

@vilgotf vilgotf left a 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?

util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Show resolved Hide resolved
util/src/builder/callback_data.rs Show resolved Hide resolved
util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
util/src/builder/callback_data.rs Show resolved Hide resolved
util/src/builder/callback_data.rs Show resolved Hide resolved
util/src/builder/callback_data.rs Show resolved Hide resolved
baptiste0928 and others added 2 commits October 2, 2021 15:12
Co-authored-by: Vilgot Fredenberg <vilgot@fredenberg.xyz>
Copy link
Member

@vilgotf vilgotf left a 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)

@baptiste0928
Copy link
Member Author

No problem, changes reverted. (oops I wrote half of the commit message in French)

vilgotf
vilgotf previously approved these changes Oct 2, 2021
Copy link
Member

@vilgotf vilgotf left a 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

Copy link
Contributor

@7596ff 7596ff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more thing

util/src/builder/callback_data.rs Outdated Show resolved Hide resolved
@7596ff 7596ff merged commit 98e97de into twilight-rs:main Oct 2, 2021
@baptiste0928 baptiste0928 deleted the callback-data-builder branch October 2, 2021 18:23
MaxOhn pushed a commit to MaxOhn/twilight that referenced this pull request Oct 6, 2021
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>
7596ff added a commit that referenced this pull request Oct 7, 2021
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
@vilgotf vilgotf mentioned this pull request Oct 24, 2021
7 tasks
@zeylahellyer zeylahellyer added this to the Builder Restructuring milestone Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-model Affects the model crate t-feature Addition of a new feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add a builder for slash command callbacks
6 participants