Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ enabled via feature flags.
### Builder

The `builder` feature enables builders for large structs. At the time of
writing, it contains the following builders:
writing, it contains the following:

- [`CommandBuilder`]
- [`EmbedBuilder`]
- [`InteractionResponseData`]
- [`interaction_response`] builders module
- [`message`] component builders module

#### Command example

Expand Down Expand Up @@ -145,4 +147,5 @@ let timestamp = user.timestamp();

[`CommandBuilder`]: https://api.twilight.rs/twilight_util/builder/command/struct.CommandBuilder.html
[`EmbedBuilder`]: https://api.twilight.rs/twilight_util/builder/embed/struct.EmbedBuilder.html
[`InteractionResponseDataBuilder`]: https://api.twilight.rs/twilight_util/builder/struct.InteractionResponseDataBuilder.html
[`interaction_response`]: https://api.twilight.rs/twilight_util/builder/interaction_response/index.html
[`message`]: https://api.twilight.rs/twilight_util/builder/message/index.html
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ twilight-http = { path = "../twilight-http" }
twilight-lavalink = { path = "../twilight-lavalink" }
twilight-model = { path = "../twilight-model" }
twilight-standby = { path = "../twilight-standby" }
twilight-util = { features = ["builder"], path = "../twilight-util" }

[[example]]
name = "cache-optimization"
Expand Down
21 changes: 6 additions & 15 deletions examples/model-webhook-slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use std::{future::Future, net::SocketAddr};
use tokio::net::TcpListener;
use twilight_model::{
application::interaction::{Interaction, InteractionType, application_command::CommandData},
http::interaction::{InteractionResponse, InteractionResponseData, InteractionResponseType},
http::interaction::{InteractionResponse, InteractionResponseType},
};
use twilight_util::builder::interaction_response::ChannelMessageBuilder;

/// Public key given from Discord.
static PUB_KEY: Lazy<VerifyingKey> = Lazy::new(|| {
Expand Down Expand Up @@ -142,24 +143,14 @@ async fn handler(data: Box<CommandData>) -> anyhow::Result<InteractionResponse>

/// Example of a handler that returns the formatted version of the interaction.
async fn debug(data: Box<CommandData>) -> anyhow::Result<InteractionResponse> {
Ok(InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(InteractionResponseData {
content: Some(format!("```rust\n{data:?}\n```")),
..Default::default()
}),
})
Ok(ChannelMessageBuilder::new()
.content(format!("```rust\n{data:?}\n```"))
.build())
}

/// Example of interaction that responds with a message saying "Vroom vroom".
async fn vroom(_: Box<CommandData>) -> anyhow::Result<InteractionResponse> {
Ok(InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(InteractionResponseData {
content: Some("Vroom vroom".to_owned()),
..Default::default()
}),
})
Ok(ChannelMessageBuilder::new().content("Vroom vroom").build())
}

#[tokio::main]
Expand Down
4 changes: 2 additions & 2 deletions twilight-http/src/client/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ impl<'a> InteractionClient<'a> {
/// Respond to an interaction, by its ID and token.
///
/// For variants of [`InteractionResponse`] that contain
/// [`InteractionResponseData`], there is an [associated builder] in the
/// [`InteractionResponseData`], there are [associated builders] in the
/// [`twilight-util`] crate.
///
/// This endpoint is not bound to the application's global rate limit.
///
/// [`InteractionResponseData`]: twilight_model::http::interaction::InteractionResponseData
/// [`twilight-util`]: https://docs.rs/twilight-util/latest/index.html
/// [associated builder]: https://docs.rs/twilight-util/latest/twilight_util/builder/struct.InteractionResponseDataBuilder.html
/// [associated builders]: https://docs.rs/twilight-util/latest/twilight_util/builder/interaction_response/index.html
pub const fn create_response(
&'a self,
interaction_id: Id<InteractionMarker>,
Expand Down
12 changes: 0 additions & 12 deletions twilight-util/src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ impl CommandBuilder {
}

/// Consume the builder, returning a [`Command`].
#[allow(clippy::missing_const_for_fn)]
#[must_use = "must be built into a command"]
pub fn build(self) -> Command {
self.0
Expand Down Expand Up @@ -245,7 +244,6 @@ impl AttachmentBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -329,7 +327,6 @@ impl BooleanBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -413,7 +410,6 @@ impl ChannelBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -505,7 +501,6 @@ impl IntegerBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -674,7 +669,6 @@ impl MentionableBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -758,7 +752,6 @@ impl NumberBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -927,7 +920,6 @@ impl RoleBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -1011,7 +1003,6 @@ impl StringBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -1183,7 +1174,6 @@ impl SubCommandBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -1275,7 +1265,6 @@ impl SubCommandGroupBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down Expand Up @@ -1359,7 +1348,6 @@ impl UserBuilder {
}

/// Consume the builder, returning the built command option.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used in a command builder"]
pub fn build(self) -> CommandOption {
self.0
Expand Down
1 change: 0 additions & 1 deletion twilight-util/src/builder/embed/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ impl EmbedAuthorBuilder {
}

/// Build into an embed author.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used as part of an embed builder"]
pub fn build(self) -> EmbedAuthor {
self.0
Expand Down
1 change: 0 additions & 1 deletion twilight-util/src/builder/embed/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl EmbedFieldBuilder {
}

/// Build into an embed field.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used as part of an embed builder"]
pub fn build(self) -> EmbedField {
self.0
Expand Down
1 change: 0 additions & 1 deletion twilight-util/src/builder/embed/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl EmbedFooterBuilder {
}

/// Build into an embed footer.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used as part of an embed builder"]
pub fn build(self) -> EmbedFooter {
self.0
Expand Down
3 changes: 0 additions & 3 deletions twilight-util/src/builder/embed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ impl EmbedBuilder {
}

/// Build this into an embed.
#[allow(clippy::missing_const_for_fn)]
#[must_use = "should be used as part of something like a message"]
pub fn build(self) -> Embed {
self.0
Expand Down Expand Up @@ -237,7 +236,6 @@ impl EmbedBuilder {
/// .build();
/// # Ok(()) }
/// ```
#[allow(clippy::missing_const_for_fn)]
pub fn image(mut self, image_source: ImageSource) -> Self {
self.0.image = Some(EmbedImage {
height: None,
Expand Down Expand Up @@ -267,7 +265,6 @@ impl EmbedBuilder {
/// .build();
/// # Ok(()) }
/// ```
#[allow(clippy::missing_const_for_fn)]
pub fn thumbnail(mut self, image_source: ImageSource) -> Self {
self.0.thumbnail = Some(EmbedThumbnail {
height: None,
Expand Down
Loading