diff --git a/examples/e06_sample_bot_structure/src/commands/math.rs b/examples/e06_sample_bot_structure/src/commands/math.rs index 27e0d0c1074..6376dfe45dc 100644 --- a/examples/e06_sample_bot_structure/src/commands/math.rs +++ b/examples/e06_sample_bot_structure/src/commands/math.rs @@ -10,7 +10,7 @@ pub async fn multiply(ctx: &Context, msg: &Message, mut args: Args) -> CommandRe let product = one * two; - msg.channel_id.say(&ctx.http, product).await?; + msg.channel_id.say(&ctx.http, product.to_string()).await?; Ok(()) } diff --git a/examples/e13_parallel_loops/src/main.rs b/examples/e13_parallel_loops/src/main.rs index fbcd64b37ab..3a2e7d46232 100644 --- a/examples/e13_parallel_loops/src/main.rs +++ b/examples/e13_parallel_loops/src/main.rs @@ -82,10 +82,10 @@ async fn log_system_load(ctx: Arc) { .send_message(&ctx, |m| { m.embed(|e| { e.title("System Resource Load") - .field("CPU Load Average", format!("{:.2}%", cpu_load.one * 10.0), false) + .field("CPU Load Average", &format!("{:.2}%", cpu_load.one * 10.0), false) .field( "Memory Usage", - format!( + &format!( "{:.2} MB Free out of {:.2} MB", mem_use.free as f32 / 1000.0, mem_use.total as f32 / 1000.0 @@ -104,7 +104,7 @@ async fn set_status_to_current_time(ctx: Arc) { let current_time = Utc::now(); let formatted_time = current_time.to_rfc2822(); - ctx.set_activity(Activity::playing(&formatted_time)).await; + ctx.set_activity(Activity::playing(formatted_time)).await; } #[tokio::main] diff --git a/examples/e17_message_components/src/main.rs b/examples/e17_message_components/src/main.rs index cf9c3b0a462..83b48ba8857 100644 --- a/examples/e17_message_components/src/main.rs +++ b/examples/e17_message_components/src/main.rs @@ -130,7 +130,7 @@ impl Sound { let mut b = CreateButton::default(); b.custom_id(self.to_string().to_ascii_lowercase()); b.emoji(self.emoji()); - b.label(self); + b.label(self.to_string()); b.style(ButtonStyle::Primary); b } diff --git a/src/builder/add_member.rs b/src/builder/add_member.rs index f5929decc3d..de7a9f342b7 100644 --- a/src/builder/add_member.rs +++ b/src/builder/add_member.rs @@ -13,8 +13,8 @@ impl AddMember { /// Sets the OAuth2 access token for this request. /// /// Requires the access token to have the `guilds.join` scope granted. - pub fn access_token(&mut self, access_token: impl ToString) -> &mut Self { - self.0.insert("access_token", Value::from(access_token.to_string())); + pub fn access_token(&mut self, access_token: impl Into) -> &mut Self { + self.0.insert("access_token", Value::String(access_token.into())); self } @@ -23,8 +23,8 @@ impl AddMember { /// Requires the [Manage Nicknames] permission. /// /// [Manage Nicknames]: crate::model::permissions::Permissions::MANAGE_NICKNAMES - pub fn nickname(&mut self, nickname: impl ToString) -> &mut Self { - self.0.insert("nick", Value::from(nickname.to_string())); + pub fn nickname(&mut self, nickname: impl Into) -> &mut Self { + self.0.insert("nick", Value::String(nickname.into())); self } diff --git a/src/builder/create_allowed_mentions.rs b/src/builder/create_allowed_mentions.rs index 57273a9a80c..bfe8b708d9e 100644 --- a/src/builder/create_allowed_mentions.rs +++ b/src/builder/create_allowed_mentions.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::json::prelude::*; use crate::model::id::{RoleId, UserId}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum ParseValue { #[serde(rename = "everyone")] Everyone, diff --git a/src/builder/create_application_command.rs b/src/builder/create_application_command.rs index 15df6126927..a7d73c8d282 100644 --- a/src/builder/create_application_command.rs +++ b/src/builder/create_application_command.rs @@ -27,8 +27,8 @@ impl CreateApplicationCommandOption { /// Sets the name of the option. /// /// **Note**: Must be between 1 and 32 lowercase characters, matching `r"^[\w-]{1,32}$"`. - pub fn name(&mut self, name: D) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } @@ -54,8 +54,8 @@ impl CreateApplicationCommandOption { /// Sets the description for the option. /// /// **Note**: Must be between 1 and 100 characters. - pub fn description(&mut self, description: D) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } @@ -101,9 +101,9 @@ impl CreateApplicationCommandOption { /// Adds an optional int-choice. /// /// **Note**: There can be no more than 25 choices set. Name must be between 1 and 100 characters. Value must be between -2^53 and 2^53. - pub fn add_int_choice(&mut self, name: D, value: i32) -> &mut Self { + pub fn add_int_choice(&mut self, name: impl Into, value: i32) -> &mut Self { let choice = json!({ - "name": name.to_string(), + "name": name.into(), "value" : value }); self.add_choice(choice) @@ -130,10 +130,14 @@ impl CreateApplicationCommandOption { /// Adds an optional string-choice. /// /// **Note**: There can be no more than 25 choices set. Name must be between 1 and 100 characters. Value must be up to 100 characters. - pub fn add_string_choice(&mut self, name: D, value: E) -> &mut Self { + pub fn add_string_choice( + &mut self, + name: impl Into, + value: impl Into, + ) -> &mut Self { let choice = json!({ - "name": name.to_string(), - "value": value.to_string() + "name": name.into(), + "value": value.into() }); self.add_choice(choice) } @@ -159,9 +163,9 @@ impl CreateApplicationCommandOption { /// Adds an optional number-choice. /// /// **Note**: There can be no more than 25 choices set. Name must be between 1 and 100 characters. Value must be between -2^53 and 2^53. - pub fn add_number_choice(&mut self, name: D, value: f64) -> &mut Self { + pub fn add_number_choice(&mut self, name: impl Into, value: f64) -> &mut Self { let choice = json!({ - "name": name.to_string(), + "name": name.into(), "value" : value }); self.add_choice(choice) @@ -287,8 +291,8 @@ impl CreateApplicationCommand { /// Specifies the name of the application command. /// /// **Note**: Must be between 1 and 32 lowercase characters, matching `r"^[\w-]{1,32}$"`. Two global commands of the same app cannot have the same name. Two guild-specific commands of the same app cannot have the same name. - pub fn name(&mut self, name: D) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } @@ -320,7 +324,7 @@ impl CreateApplicationCommand { /// Specifies the default permissions required to execute the command. pub fn default_member_permissions(&mut self, permissions: Permissions) -> &mut Self { - self.0.insert("default_member_permissions", Value::from(permissions.bits().to_string())); + self.0.insert("default_member_permissions", Value::String(permissions.bits().to_string())); self } @@ -335,8 +339,8 @@ impl CreateApplicationCommand { /// Specifies the description of the application command. /// /// **Note**: Must be between 1 and 100 characters long. - pub fn description(&mut self, description: D) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } diff --git a/src/builder/create_channel.rs b/src/builder/create_channel.rs index 6e2d1c7769e..0f5022832a9 100644 --- a/src/builder/create_channel.rs +++ b/src/builder/create_channel.rs @@ -16,8 +16,8 @@ impl CreateChannel { /// Specify how to call this new channel. /// /// **Note**: Must be between 2 and 100 characters long. - pub fn name(&mut self, name: D) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } @@ -38,8 +38,8 @@ impl CreateChannel { /// Set an interesting topic. /// /// **Note**: Must be between 0 and 1000 characters long. - pub fn topic(&mut self, topic: D) -> &mut Self { - self.0.insert("topic", Value::from(topic.to_string())); + pub fn topic(&mut self, topic: impl Into) -> &mut Self { + self.0.insert("topic", Value::String(topic.into())); self } diff --git a/src/builder/create_components.rs b/src/builder/create_components.rs index 5af87e807fb..d544e11d262 100644 --- a/src/builder/create_components.rs +++ b/src/builder/create_components.rs @@ -161,20 +161,20 @@ impl CreateButton { } /// The label of the button. - pub fn label(&mut self, label: D) -> &mut Self { - self.0.insert("label", Value::from(label.to_string())); + pub fn label(&mut self, label: impl Into) -> &mut Self { + self.0.insert("label", Value::String(label.into())); self } /// Sets the custom id of the button, a developer-defined identifier. - pub fn custom_id(&mut self, id: D) -> &mut Self { - self.0.insert("custom_id", Value::from(id.to_string())); + pub fn custom_id(&mut self, id: impl Into) -> &mut Self { + self.0.insert("custom_id", Value::String(id.into())); self } /// The url for url style button. - pub fn url(&mut self, url: D) -> &mut Self { - self.0.insert("url", Value::from(url.to_string())); + pub fn url(&mut self, url: impl Into) -> &mut Self { + self.0.insert("url", Value::String(url.into())); self } @@ -188,18 +188,18 @@ impl CreateButton { match emoji { ReactionType::Unicode(u) => { - map.insert("name".to_string(), Value::from(u)); + map.insert("name".into(), Value::from(u)); }, ReactionType::Custom { animated, id, name, } => { - map.insert("animated".to_string(), Value::from(animated)); - map.insert("id".to_string(), Value::from(id.to_string())); + map.insert("animated".into(), Value::from(animated)); + map.insert("id".into(), Value::String(id.to_string())); if let Some(name) = name { - map.insert("name".to_string(), Value::from(name)); + map.insert("name".into(), Value::String(name)); } }, }; @@ -230,14 +230,14 @@ pub struct CreateSelectMenu(pub HashMap<&'static str, Value>); impl CreateSelectMenu { /// The placeholder of the select menu. - pub fn placeholder(&mut self, label: D) -> &mut Self { - self.0.insert("placeholder", Value::from(label.to_string())); + pub fn placeholder(&mut self, label: impl Into) -> &mut Self { + self.0.insert("placeholder", Value::String(label.into())); self } /// Sets the custom id of the select menu, a developer-defined identifier. - pub fn custom_id(&mut self, id: D) -> &mut Self { - self.0.insert("custom_id", Value::from(id.to_string())); + pub fn custom_id(&mut self, id: impl Into) -> &mut Self { + self.0.insert("custom_id", Value::String(id.into())); self } @@ -329,27 +329,27 @@ pub struct CreateSelectMenuOption(pub HashMap<&'static str, Value>); impl CreateSelectMenuOption { /// Creates an option. - pub fn new(label: L, value: V) -> Self { + pub fn new(label: impl Into, value: impl Into) -> Self { let mut opt = Self::default(); opt.label(label).value(value); opt } /// Sets the label of this option. - pub fn label(&mut self, label: D) -> &mut Self { - self.0.insert("label", Value::from(label.to_string())); + pub fn label(&mut self, label: impl Into) -> &mut Self { + self.0.insert("label", Value::String(label.into())); self } /// Sets the value of this option. - pub fn value(&mut self, value: D) -> &mut Self { - self.0.insert("value", Value::from(value.to_string())); + pub fn value(&mut self, value: impl Into) -> &mut Self { + self.0.insert("value", Value::String(value.into())); self } /// Sets the description shown on this option. - pub fn description(&mut self, description: D) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } @@ -363,18 +363,18 @@ impl CreateSelectMenuOption { match emoji { ReactionType::Unicode(u) => { - map.insert("name".to_string(), Value::from(u)); + map.insert("name".into(), Value::String(u)); }, ReactionType::Custom { animated, id, name, } => { - map.insert("animated".to_string(), Value::from(animated)); - map.insert("id".to_string(), Value::from(id.to_string())); + map.insert("animated".into(), Value::from(animated)); + map.insert("id".into(), Value::String(id.to_string())); if let Some(name) = name { - map.insert("name".to_string(), Value::from(name)); + map.insert("name".into(), Value::from(name)); } }, }; @@ -398,8 +398,8 @@ pub struct CreateInputText(pub HashMap<&'static str, Value>); impl CreateInputText { /// Sets the custom id of the input text, a developer-defined identifier. - pub fn custom_id(&mut self, id: D) -> &mut Self { - self.0.insert("custom_id", Value::from(id.to_string())); + pub fn custom_id(&mut self, id: impl Into) -> &mut Self { + self.0.insert("custom_id", Value::from(id.into())); self } @@ -410,14 +410,14 @@ impl CreateInputText { } /// Sets the label of this input text. - pub fn label(&mut self, label: D) -> &mut Self { - self.0.insert("label", Value::from(label.to_string())); + pub fn label(&mut self, label: impl Into) -> &mut Self { + self.0.insert("label", Value::String(label.into())); self } /// Sets the placeholder of this input text. - pub fn placeholder(&mut self, label: D) -> &mut Self { - self.0.insert("placeholder", Value::from(label.to_string())); + pub fn placeholder(&mut self, label: impl Into) -> &mut Self { + self.0.insert("placeholder", Value::String(label.into())); self } @@ -434,8 +434,8 @@ impl CreateInputText { } /// Sets the value of this input text. - pub fn value(&mut self, value: D) -> &mut Self { - self.0.insert("value", Value::from(value.to_string())); + pub fn value(&mut self, value: impl Into) -> &mut Self { + self.0.insert("value", Value::String(value.into())); self } diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs index 37531b33054..26e048bbb8f 100644 --- a/src/builder/create_embed.rs +++ b/src/builder/create_embed.rs @@ -102,8 +102,8 @@ impl CreateEmbed { /// /// **Note**: This can't be longer than 4096 characters. #[inline] - pub fn description(&mut self, description: D) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } @@ -113,37 +113,26 @@ impl CreateEmbed { /// **Note**: Maximum amount of characters you can put is 256 in a field /// name and 1024 in a field value. #[inline] - pub fn field(&mut self, name: T, value: U, inline: bool) -> &mut Self - where - T: ToString, - U: ToString, - { - self._field(name.to_string(), value.to_string(), inline); - self - } - - fn _field(&mut self, name: String, value: String, inline: bool) { - { - let entry = self.0.entry("fields").or_insert_with(|| Value::from(Vec::::new())); - - if let Value::Array(ref mut inner) = *entry { - inner.push(json!({ - "inline": inline, - "name": name, - "value": value, - })); - } + pub fn field(&mut self, name: &str, value: &str, inline: bool) -> &mut Self { + let entry = self.0.entry("fields").or_insert_with(|| Value::from(Vec::::new())); + + if let Value::Array(ref mut inner) = *entry { + inner.push(json!({ + "inline": inline, + "name": name, + "value": value, + })); } + + self } /// Adds multiple fields at once. /// /// This is sugar to reduce the need of calling [`Self::field`] manually multiple times. - pub fn fields(&mut self, fields: It) -> &mut Self + pub fn fields<'a, 'b, It>(&mut self, fields: It) -> &mut Self where - It: IntoIterator, - T: ToString, - U: ToString, + It: IntoIterator, { for (name, value, inline) in fields { self.field(name, value, inline); @@ -174,7 +163,7 @@ impl CreateEmbed { self } - fn url_object(&mut self, name: &'static str, url: String) -> &mut Self { + fn url_object(&mut self, name: &'static str, url: &str) -> &mut Self { let obj = json!({ "url": url, }); @@ -185,16 +174,16 @@ impl CreateEmbed { /// Set the image associated with the embed. This only supports HTTP(S). #[inline] - pub fn image(&mut self, url: S) -> &mut Self { - self.url_object("image", url.to_string()); + pub fn image(&mut self, url: &str) -> &mut Self { + self.url_object("image", url); self } /// Set the thumbnail of the embed. This only supports HTTP(S). #[inline] - pub fn thumbnail(&mut self, url: S) -> &mut Self { - self.url_object("thumbnail", url.to_string()); + pub fn thumbnail(&mut self, url: &str) -> &mut Self { + self.url_object("thumbnail", url); self } @@ -300,20 +289,20 @@ impl CreateEmbed { } fn _timestamp(&mut self, timestamp: Timestamp) { - self.0.insert("timestamp", Value::from(timestamp.to_string())); + self.0.insert("timestamp", Value::String(timestamp.to_string())); } /// Set the title of the embed. #[inline] - pub fn title(&mut self, title: D) -> &mut Self { - self.0.insert("title", Value::from(title.to_string())); + pub fn title(&mut self, title: impl Into) -> &mut Self { + self.0.insert("title", Value::String(title.into())); self } /// Set the URL to direct to when clicking on the title. #[inline] - pub fn url(&mut self, url: S) -> &mut Self { - self.0.insert("url", Value::from(url.to_string())); + pub fn url(&mut self, url: impl Into) -> &mut Self { + self.0.insert("url", Value::String(url.into())); self } @@ -324,10 +313,10 @@ impl CreateEmbed { /// /// [`ChannelId::send_files`]: crate::model::id::ChannelId::send_files #[inline] - pub fn attachment(&mut self, filename: S) -> &mut Self { - let mut filename = filename.to_string(); + pub fn attachment(&mut self, filename: impl Into) -> &mut Self { + let mut filename = filename.into(); filename.insert_str(0, "attachment://"); - self.url_object("image", filename); + self.url_object("image", &filename); self } @@ -337,7 +326,7 @@ impl Default for CreateEmbed { /// Creates a builder with default values, setting the `type` to `rich`. fn default() -> CreateEmbed { let mut map = HashMap::new(); - map.insert("type", Value::from("rich".to_string())); + map.insert("type", Value::String("rich".into())); CreateEmbed(map) } @@ -375,7 +364,7 @@ impl From for CreateEmbed { } for field in embed.fields { - b.field(field.name, field.value, field.inline); + b.field(&field.name, &field.value, field.inline); } if let Some(image) = embed.image { @@ -422,20 +411,20 @@ pub struct CreateEmbedAuthor(pub HashMap<&'static str, Value>); impl CreateEmbedAuthor { /// Set the URL of the author's icon. - pub fn icon_url(&mut self, icon_url: S) -> &mut Self { - self.0.insert("icon_url", Value::from(icon_url.to_string())); + pub fn icon_url(&mut self, icon_url: impl Into) -> &mut Self { + self.0.insert("icon_url", Value::String(icon_url.into())); self } /// Set the author's name. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } /// Set the author's URL. - pub fn url(&mut self, url: S) -> &mut Self { - self.0.insert("url", Value::from(url.to_string())); + pub fn url(&mut self, url: impl Into) -> &mut Self { + self.0.insert("url", Value::String(url.into())); self } } @@ -451,14 +440,14 @@ pub struct CreateEmbedFooter(pub HashMap<&'static str, Value>); impl CreateEmbedFooter { /// Set the icon URL's value. This only supports HTTP(S). - pub fn icon_url(&mut self, icon_url: S) -> &mut Self { - self.0.insert("icon_url", Value::from(icon_url.to_string())); + pub fn icon_url(&mut self, icon_url: impl Into) -> &mut Self { + self.0.insert("icon_url", Value::String(icon_url.into())); self } /// Set the footer's text. - pub fn text(&mut self, text: S) -> &mut Self { - self.0.insert("text", Value::from(text.to_string())); + pub fn text(&mut self, text: impl Into) -> &mut Self { + self.0.insert("text", Value::String(text.into())); self } } diff --git a/src/builder/create_interaction_response.rs b/src/builder/create_interaction_response.rs index ece7451f628..cbb2e0130ed 100644 --- a/src/builder/create_interaction_response.rs +++ b/src/builder/create_interaction_response.rs @@ -96,8 +96,8 @@ impl<'a> CreateInteractionResponseData<'a> { /// /// **Note**: Message contents must be under 2000 unicode code points. #[inline] - pub fn content(&mut self, content: D) -> &mut Self { - self._content(content.to_string()) + pub fn content(&mut self, content: impl Into) -> &mut Self { + self._content(content.into()) } fn _content(&mut self, content: String) -> &mut Self { @@ -221,14 +221,14 @@ impl<'a> CreateInteractionResponseData<'a> { } /// Sets the custom id for modal interactions - pub fn custom_id(&mut self, id: D) -> &mut Self { - self.0.insert("custom_id", Value::String(id.to_string())); + pub fn custom_id(&mut self, id: impl Into) -> &mut Self { + self.0.insert("custom_id", Value::String(id.into())); self } /// Sets the title for modal interactions - pub fn title(&mut self, title: D) -> &mut Self { - self.0.insert("title", Value::String(title.to_string())); + pub fn title(&mut self, title: impl Into) -> &mut Self { + self.0.insert("title", Value::String(title.into())); self } } @@ -258,9 +258,9 @@ impl CreateAutocompleteResponse { /// Add an int autocomplete choice. /// /// **Note**: There can be no more than 25 choices set. Name must be between 1 and 100 characters. Value must be between -2^53 and 2^53. - pub fn add_int_choice(&mut self, name: D, value: i64) -> &mut Self { + pub fn add_int_choice(&mut self, name: impl Into, value: i64) -> &mut Self { let choice = json!({ - "name": name.to_string(), + "name": name.into(), "value" : value }); self.add_choice(choice) @@ -269,10 +269,14 @@ impl CreateAutocompleteResponse { /// Adds a string autocomplete choice. /// /// **Note**: There can be no more than 25 choices set. Name must be between 1 and 100 characters. Value must be up to 100 characters. - pub fn add_string_choice(&mut self, name: D, value: E) -> &mut Self { + pub fn add_string_choice( + &mut self, + name: impl Into, + value: impl Into, + ) -> &mut Self { let choice = json!({ - "name": name.to_string(), - "value": value.to_string() + "name": name.into(), + "value": value.into() }); self.add_choice(choice) } @@ -280,9 +284,9 @@ impl CreateAutocompleteResponse { /// Adds a number autocomplete choice. /// /// **Note**: There can be no more than 25 choices set. Name must be between 1 and 100 characters. Value must be between -2^53 and 2^53. - pub fn add_number_choice(&mut self, name: D, value: f64) -> &mut Self { + pub fn add_number_choice(&mut self, name: impl Into, value: f64) -> &mut Self { let choice = json!({ - "name": name.to_string(), + "name": name.into(), "value" : value }); self.add_choice(choice) diff --git a/src/builder/create_interaction_response_followup.rs b/src/builder/create_interaction_response_followup.rs index fd2ae976b82..53b65226118 100644 --- a/src/builder/create_interaction_response_followup.rs +++ b/src/builder/create_interaction_response_followup.rs @@ -22,34 +22,34 @@ impl<'a> CreateInteractionResponseFollowup<'a> { /// /// **Note**: Message contents must be under 2000 unicode code points. #[inline] - pub fn content(&mut self, content: D) -> &mut Self { - self._content(content.to_string()) + pub fn content(&mut self, content: impl Into) -> &mut Self { + self._content(content.into()) } fn _content(&mut self, content: String) -> &mut Self { - self.0.insert("content", Value::from(content)); + self.0.insert("content", Value::String(content)); self } /// Override the default username of the webhook #[inline] - pub fn username(&mut self, username: D) -> &mut Self { - self._username(username.to_string()) + pub fn username(&mut self, username: impl Into) -> &mut Self { + self._username(username.into()) } fn _username(&mut self, username: String) -> &mut Self { - self.0.insert("username", Value::from(username)); + self.0.insert("username", Value::String(username)); self } /// Override the default avatar of the webhook #[inline] - pub fn avatar(&mut self, avatar_url: D) -> &mut Self { - self._avatar(avatar_url.to_string()) + pub fn avatar(&mut self, avatar_url: impl Into) -> &mut Self { + self._avatar(avatar_url.into()) } fn _avatar(&mut self, avatar_url: String) -> &mut Self { - self.0.insert("avatar_url", Value::from(avatar_url)); + self.0.insert("avatar_url", Value::String(avatar_url)); self } /// Set whether the message is text-to-speech. diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs index 38bdc58feea..c3f4abf6c4c 100644 --- a/src/builder/create_message.rs +++ b/src/builder/create_message.rs @@ -62,12 +62,12 @@ impl<'a> CreateMessage<'a> { /// /// **Note**: Message contents must be under 2000 unicode code points. #[inline] - pub fn content(&mut self, content: D) -> &mut Self { - self._content(content.to_string()) + pub fn content(&mut self, content: impl Into) -> &mut Self { + self._content(content.into()) } fn _content(&mut self, content: String) -> &mut Self { - self.0.insert("content", Value::from(content)); + self.0.insert("content", Value::String(content)); self } diff --git a/src/builder/create_scheduled_event.rs b/src/builder/create_scheduled_event.rs index b8bbef27f6d..0c5fe66da76 100644 --- a/src/builder/create_scheduled_event.rs +++ b/src/builder/create_scheduled_event.rs @@ -29,14 +29,14 @@ impl CreateScheduledEvent { } /// Sets the name of the scheduled event. Required to be set for event creation. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } /// Sets the description of the scheduled event. - pub fn description(&mut self, description: S) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } @@ -73,9 +73,9 @@ impl CreateScheduledEvent { /// /// [`kind`]: CreateScheduledEvent::kind /// [`External`]: ScheduledEventType::External - pub fn location(&mut self, location: S) -> &mut Self { + pub fn location(&mut self, location: impl Into) -> &mut Self { let obj = json!({ - "location": location.to_string(), + "location": location.into(), }); self.0.insert("entity_metadata", obj); self diff --git a/src/builder/create_stage_instance.rs b/src/builder/create_stage_instance.rs index e7e486a12da..2da40eb2bca 100644 --- a/src/builder/create_stage_instance.rs +++ b/src/builder/create_stage_instance.rs @@ -16,8 +16,8 @@ impl CreateStageInstance { } /// Sets the topic of the stage channel instance. - pub fn topic(&mut self, topic: D) -> &mut Self { - self.0.insert("topic", Value::from(topic.to_string())); + pub fn topic(&mut self, topic: impl Into) -> &mut Self { + self.0.insert("topic", Value::String(topic.into())); self } diff --git a/src/builder/create_sticker.rs b/src/builder/create_sticker.rs index 8b47eb18a09..47871cf9d81 100644 --- a/src/builder/create_sticker.rs +++ b/src/builder/create_sticker.rs @@ -22,24 +22,24 @@ impl<'a> CreateSticker<'a> { /// The name of the sticker to set. /// /// **Note**: Must be between 2 and 30 characters long. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } /// The description of the sticker. /// /// **Note**: If not empty, must be between 2 and 100 characters long. - pub fn description(&mut self, description: S) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } /// The Discord name of a unicode emoji representing the sticker's expression. /// /// **Note**: Must be between 2 and 200 characters long. - pub fn tags(&mut self, tags: S) -> &mut Self { - self.0.insert("tags", Value::from(tags.to_string())); + pub fn tags(&mut self, tags: impl Into) -> &mut Self { + self.0.insert("tags", Value::String(tags.into())); self } diff --git a/src/builder/create_thread.rs b/src/builder/create_thread.rs index fd92837c2ab..b4782b28fd9 100644 --- a/src/builder/create_thread.rs +++ b/src/builder/create_thread.rs @@ -10,8 +10,8 @@ impl CreateThread { /// The name of the thread. /// /// **Note**: Must be between 2 and 100 characters long. - pub fn name(&mut self, name: D) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } diff --git a/src/builder/edit_channel.rs b/src/builder/edit_channel.rs index f57d063019f..bf2e1860632 100644 --- a/src/builder/edit_channel.rs +++ b/src/builder/edit_channel.rs @@ -69,8 +69,8 @@ impl EditChannel { /// The name of the channel. /// /// Must be between 2 and 100 characters long. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } @@ -87,8 +87,8 @@ impl EditChannel { /// This is for [text] channels only. /// /// [text]: crate::model::channel::ChannelType::Text - pub fn topic(&mut self, topic: S) -> &mut Self { - self.0.insert("topic", Value::from(topic.to_string())); + pub fn topic(&mut self, topic: impl Into) -> &mut Self { + self.0.insert("topic", Value::String(topic.into())); self } diff --git a/src/builder/edit_guild.rs b/src/builder/edit_guild.rs index d88b108da80..b91eb5c2417 100644 --- a/src/builder/edit_guild.rs +++ b/src/builder/edit_guild.rs @@ -76,8 +76,8 @@ impl EditGuild { /// Set the name of the guild. /// /// **Note**: Must be between (and including) 2-100 characters. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } @@ -87,8 +87,8 @@ impl EditGuild { /// You can check this through a guild's [`features`] list. /// /// [`features`]: crate::model::guild::Guild::features - pub fn description(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn description(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } diff --git a/src/builder/edit_guild_welcome_screen.rs b/src/builder/edit_guild_welcome_screen.rs index b2f29e6f155..38166973c15 100644 --- a/src/builder/edit_guild_welcome_screen.rs +++ b/src/builder/edit_guild_welcome_screen.rs @@ -19,8 +19,8 @@ impl EditGuildWelcomeScreen { } /// The server description shown in the welcome screen. - pub fn description(&mut self, description: D) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } @@ -76,8 +76,8 @@ impl CreateGuildWelcomeChannel { } /// The description shown for the channel. It is required. - pub fn description(&mut self, description: D) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::from(description.into())); self } diff --git a/src/builder/edit_interaction_response.rs b/src/builder/edit_interaction_response.rs index f05200fe215..f9db4bddeb3 100644 --- a/src/builder/edit_interaction_response.rs +++ b/src/builder/edit_interaction_response.rs @@ -15,12 +15,12 @@ impl EditInteractionResponse { /// /// **Note**: Message contents must be under 2000 unicode code points. #[inline] - pub fn content(&mut self, content: D) -> &mut Self { - self._content(content.to_string()) + pub fn content(&mut self, content: impl Into) -> &mut Self { + self._content(content.into()) } fn _content(&mut self, content: String) -> &mut Self { - self.0.insert("content", Value::from(content)); + self.0.insert("content", Value::String(content)); self } diff --git a/src/builder/edit_member.rs b/src/builder/edit_member.rs index 99b261abf04..be6ca0b0f10 100644 --- a/src/builder/edit_member.rs +++ b/src/builder/edit_member.rs @@ -40,8 +40,8 @@ impl EditMember { /// Requires the [Manage Nicknames] permission. /// /// [Manage Nicknames]: crate::model::permissions::Permissions::MANAGE_NICKNAMES - pub fn nickname(&mut self, nickname: S) -> &mut Self { - self.0.insert("nick", Value::from(nickname.to_string())); + pub fn nickname(&mut self, nickname: impl Into) -> &mut Self { + self.0.insert("nick", Value::String(nickname.into())); self } diff --git a/src/builder/edit_message.rs b/src/builder/edit_message.rs index 2029fe72898..3881f22de9d 100644 --- a/src/builder/edit_message.rs +++ b/src/builder/edit_message.rs @@ -38,8 +38,8 @@ impl<'a> EditMessage<'a> { /// /// **Note**: Message contents must be under 2000 unicode code points. #[inline] - pub fn content(&mut self, content: D) -> &mut Self { - self.0.insert("content", Value::from(content.to_string())); + pub fn content(&mut self, content: impl Into) -> &mut Self { + self.0.insert("content", Value::String(content.into())); self } diff --git a/src/builder/edit_profile.rs b/src/builder/edit_profile.rs index 65bfd7d520d..65ea1f261da 100644 --- a/src/builder/edit_profile.rs +++ b/src/builder/edit_profile.rs @@ -95,8 +95,8 @@ impl EditProfile { /// and current discriminator, a new unique discriminator will be assigned. /// If there are no available discriminators with the requested username, /// an error will occur. - pub fn username(&mut self, username: S) -> &mut Self { - self.0.insert("username", Value::from(username.to_string())); + pub fn username(&mut self, username: impl Into) -> &mut Self { + self.0.insert("username", Value::from(username.into())); self } } diff --git a/src/builder/edit_role.rs b/src/builder/edit_role.rs index ebcb2e314d0..e626a75dcf7 100644 --- a/src/builder/edit_role.rs +++ b/src/builder/edit_role.rs @@ -102,8 +102,8 @@ impl EditRole { } /// The name of the role to set. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } @@ -121,9 +121,9 @@ impl EditRole { } /// The unicode emoji to set as the role image. - pub fn unicode_emoji(&mut self, unicode_emoji: S) -> &mut Self { + pub fn unicode_emoji(&mut self, unicode_emoji: impl Into) -> &mut Self { self.0.remove("icon"); - self.0.insert("unicode_emoji", Value::String(unicode_emoji.to_string())); + self.0.insert("unicode_emoji", Value::String(unicode_emoji.into())); self } diff --git a/src/builder/edit_scheduled_event.rs b/src/builder/edit_scheduled_event.rs index 967d595a244..4d3ad78dcac 100644 --- a/src/builder/edit_scheduled_event.rs +++ b/src/builder/edit_scheduled_event.rs @@ -30,14 +30,14 @@ impl EditScheduledEvent { } /// Sets the name of the scheduled event. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } /// Sets the description of the scheduled event. - pub fn description(&mut self, description: S) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::from(description.into())); self } @@ -116,9 +116,9 @@ impl EditScheduledEvent { /// /// [`kind`]: EditScheduledEvent::kind /// [`External`]: ScheduledEventType::External - pub fn location(&mut self, location: S) -> &mut Self { + pub fn location(&mut self, location: impl Into) -> &mut Self { let obj = json!({ - "location": location.to_string(), + "location": location.into(), }); self.0.insert("entity_metadata", obj); self diff --git a/src/builder/edit_stage_instance.rs b/src/builder/edit_stage_instance.rs index 1ca911a03c2..5f656b38d23 100644 --- a/src/builder/edit_stage_instance.rs +++ b/src/builder/edit_stage_instance.rs @@ -10,8 +10,8 @@ pub struct EditStageInstance(pub HashMap<&'static str, Value>); impl EditStageInstance { /// Sets the topic of the stage channel instance. - pub fn topic(&mut self, topic: D) -> &mut Self { - self.0.insert("topic", Value::from(topic.to_string())); + pub fn topic(&mut self, topic: impl Into) -> &mut Self { + self.0.insert("topic", Value::String(topic.into())); self } diff --git a/src/builder/edit_sticker.rs b/src/builder/edit_sticker.rs index 44b5ab6d6b3..6ed6b5912e4 100644 --- a/src/builder/edit_sticker.rs +++ b/src/builder/edit_sticker.rs @@ -23,24 +23,24 @@ impl EditSticker { /// The name of the sticker to set. /// /// **Note**: Must be between 2 and 30 characters long. - pub fn name(&mut self, name: S) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } /// The description of the sticker. /// /// **Note**: If not empty, must be between 2 and 100 characters long. - pub fn description(&mut self, description: S) -> &mut Self { - self.0.insert("description", Value::from(description.to_string())); + pub fn description(&mut self, description: impl Into) -> &mut Self { + self.0.insert("description", Value::String(description.into())); self } /// The Discord name of a unicode emoji representing the sticker's expression. /// /// **Note**: Must be between 2 and 200 characters long. - pub fn tags(&mut self, tags: S) -> &mut Self { - self.0.insert("tags", Value::from(tags.to_string())); + pub fn tags(&mut self, tags: impl Into) -> &mut Self { + self.0.insert("tags", Value::String(tags.into())); self } } diff --git a/src/builder/edit_thread.rs b/src/builder/edit_thread.rs index bb1648a73cd..5c4de837de8 100644 --- a/src/builder/edit_thread.rs +++ b/src/builder/edit_thread.rs @@ -9,8 +9,8 @@ impl EditThread { /// The name of the thread. /// /// **Note**: Must be between 2 and 100 characters long. - pub fn name(&mut self, name: D) -> &mut Self { - self.0.insert("name", Value::from(name.to_string())); + pub fn name(&mut self, name: impl Into) -> &mut Self { + self.0.insert("name", Value::String(name.into())); self } diff --git a/src/builder/edit_webhook_message.rs b/src/builder/edit_webhook_message.rs index ffffc5cd66d..a178c3b5d1a 100644 --- a/src/builder/edit_webhook_message.rs +++ b/src/builder/edit_webhook_message.rs @@ -16,8 +16,8 @@ impl EditWebhookMessage { /// /// **Note**: Message contents must be under 2000 unicode code points. #[inline] - pub fn content(&mut self, content: D) -> &mut Self { - self.0.insert("content", Value::from(content.to_string())); + pub fn content(&mut self, content: impl Into) -> &mut Self { + self.0.insert("content", Value::String(content.into())); self } diff --git a/src/builder/execute_webhook.rs b/src/builder/execute_webhook.rs index cb46061f625..3b7a9a593b4 100644 --- a/src/builder/execute_webhook.rs +++ b/src/builder/execute_webhook.rs @@ -87,8 +87,8 @@ impl<'a> ExecuteWebhook<'a> { /// # Ok(()) /// # } /// ``` - pub fn avatar_url(&mut self, avatar_url: S) -> &mut Self { - self.0.insert("avatar_url", Value::from(avatar_url.to_string())); + pub fn avatar_url(&mut self, avatar_url: impl Into) -> &mut Self { + self.0.insert("avatar_url", Value::String(avatar_url.into())); self } @@ -117,8 +117,8 @@ impl<'a> ExecuteWebhook<'a> { /// # Ok(()) /// # } /// ``` - pub fn content(&mut self, content: S) -> &mut Self { - self.0.insert("content", Value::from(content.to_string())); + pub fn content(&mut self, content: impl Into) -> &mut Self { + self.0.insert("content", Value::String(content.into())); self } @@ -259,8 +259,8 @@ impl<'a> ExecuteWebhook<'a> { /// # Ok(()) /// # } /// ``` - pub fn username(&mut self, username: S) -> &mut Self { - self.0.insert("username", Value::from(username.to_string())); + pub fn username(&mut self, username: impl Into) -> &mut Self { + self.0.insert("username", Value::String(username.into())); self } diff --git a/src/framework/standard/configuration.rs b/src/framework/standard/configuration.rs index fa59e155dae..18f6a286798 100644 --- a/src/framework/standard/configuration.rs +++ b/src/framework/standard/configuration.rs @@ -453,8 +453,8 @@ impl Configuration { /// /// let framework = StandardFramework::new().configure(|c| c.prefix("!")); /// ``` - pub fn prefix(&mut self, prefix: impl ToString) -> &mut Self { - let p = prefix.to_string(); + pub fn prefix(&mut self, prefix: impl Into) -> &mut Self { + let p = prefix.into(); self.prefixes = if p.is_empty() { vec![] } else { vec![p] }; self diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs index c1b34051e4c..3369af3a55f 100644 --- a/src/framework/standard/help_commands.rs +++ b/src/framework/standard/help_commands.rs @@ -1051,7 +1051,7 @@ async fn send_single_command_embed( channel_id .send_message(&http, |m| { m.embed(|embed| { - embed.title(&command.name); + embed.title(command.name); embed.colour(colour); if let Some(desc) = command.description { @@ -1066,7 +1066,7 @@ async fn send_single_command_embed( format!("`{} {}`", command.name, usage) }; - embed.field(&help_options.usage_label, full_usage_text, true); + embed.field(help_options.usage_label, &full_usage_text, true); } if !command.usage_sample.is_empty() { @@ -1080,35 +1080,35 @@ async fn send_single_command_embed( let format_example = |example| format!("`{} {}`\n", command.name, example); command.usage_sample.iter().map(format_example).collect::() }; - embed.field(&help_options.usage_sample_label, full_example_text, true); + embed.field(help_options.usage_sample_label, &full_example_text, true); } - embed.field(&help_options.grouped_label, command.group_name, true); + embed.field(help_options.grouped_label, command.group_name, true); if !command.aliases.is_empty() { embed.field( - &help_options.aliases_label, - format!("`{}`", command.aliases.join("`, `")), + help_options.aliases_label, + &format!("`{}`", command.aliases.join("`, `")), true, ); } if !help_options.available_text.is_empty() && !command.availability.is_empty() { - embed.field(&help_options.available_text, &command.availability, true); + embed.field(help_options.available_text, command.availability, true); } if !command.checks.is_empty() { embed.field( - &help_options.checks_label, - format!("`{}`", command.checks.join("`, `")), + help_options.checks_label, + &format!("`{}`", command.checks.join("`, `")), true, ); } if !command.sub_commands.is_empty() { embed.field( - &help_options.sub_commands_label, - format!("`{}`", command.sub_commands.join("`, `")), + help_options.sub_commands_label, + &format!("`{}`", command.sub_commands.join("`, `")), true, ); } diff --git a/src/lib.rs b/src/lib.rs index 727d38eb807..e5457e678a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,6 @@ #![allow( // Allowed to avoid breaking changes. clippy::module_name_repetitions, - clippy::needless_pass_by_value, clippy::struct_excessive_bools, clippy::unused_self, // Allowed as they are too pedantic diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index 5c8c0b2d3e6..34938d2f790 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -661,11 +661,7 @@ impl ChannelId { /// is over the above limit, containing the number of unicode code points /// over the limit. #[inline] - pub async fn say( - self, - http: impl AsRef, - content: impl std::fmt::Display, - ) -> Result { + pub async fn say(self, http: impl AsRef, content: impl Into) -> Result { self.send_message(&http, |m| m.content(content)).await } diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 1622bfc2ce4..0f9ad63f004 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -913,11 +913,7 @@ impl GuildChannel { /// May also return [`Error::Http`] if the current user lacks permission /// to send a message to the channel. #[inline] - pub async fn say( - &self, - http: impl AsRef, - content: impl std::fmt::Display, - ) -> Result { + pub async fn say(&self, http: impl AsRef, content: impl Into) -> Result { self.id.say(&http, content).await } diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index e87ea10421a..3ab1ec86b9f 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -649,7 +649,7 @@ impl Message { pub async fn reply( &self, cache_http: impl CacheHttp, - content: impl Display, + content: impl Into, ) -> Result { self._reply(cache_http, content, Some(false)).await } @@ -675,7 +675,7 @@ impl Message { pub async fn reply_ping( &self, cache_http: impl CacheHttp, - content: impl Display, + content: impl Into, ) -> Result { self._reply(cache_http, content, Some(true)).await } @@ -713,7 +713,7 @@ impl Message { async fn _reply( &self, cache_http: impl CacheHttp, - content: impl Display, + content: impl Into, inlined: Option, ) -> Result { #[cfg(feature = "cache")] diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index 2e3d442d6a6..ada5020bd5f 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -272,7 +272,7 @@ impl PrivateChannel { /// is over the above limit, containing the number of unicode code points /// over the limit. #[inline] - pub async fn say(&self, http: impl AsRef, content: impl fmt::Display) -> Result { + pub async fn say(&self, http: impl AsRef, content: impl Into) -> Result { self.id.say(&http, content).await } diff --git a/src/model/gateway.rs b/src/model/gateway.rs index 6303c29239c..059c3dd6061 100644 --- a/src/model/gateway.rs +++ b/src/model/gateway.rs @@ -117,16 +117,13 @@ impl Activity { /// #[command] /// async fn activity(ctx: &Context, _msg: &Message, args: Args) -> CommandResult { /// let name = args.message(); - /// ctx.set_activity(Activity::playing(&name)).await; + /// ctx.set_activity(Activity::playing(name)).await; /// /// Ok(()) /// } /// ``` - pub fn playing(name: N) -> Activity - where - N: ToString, - { - Activity::new(name.to_string(), ActivityType::Playing) + pub fn playing(name: impl Into) -> Activity { + Activity::new(name.into(), ActivityType::Playing) } /// Creates an [`Activity`] struct that appears as a `Streaming ` @@ -152,19 +149,15 @@ impl Activity { /// const STREAM_URL: &str = "..."; /// /// let name = args.message(); - /// ctx.set_activity(Activity::streaming(&name, STREAM_URL)).await; + /// ctx.set_activity(Activity::streaming(name, STREAM_URL)).await; /// /// Ok(()) /// } /// ``` - pub fn streaming(name: N, url: U) -> Activity - where - N: ToString, - U: AsRef, - { + pub fn streaming(name: impl Into, url: impl AsRef) -> Activity { Activity { url: Some(Url::parse(url.as_ref()).expect("Failed to parse url")), - ..Activity::new(name.to_string(), ActivityType::Streaming) + ..Activity::new(name.into(), ActivityType::Streaming) } } @@ -188,16 +181,13 @@ impl Activity { /// #[command] /// async fn listen(ctx: &Context, _msg: &Message, args: Args) -> CommandResult { /// let name = args.message(); - /// ctx.set_activity(Activity::listening(&name)).await; + /// ctx.set_activity(Activity::listening(name)).await; /// /// Ok(()) /// } /// ``` - pub fn listening(name: N) -> Activity - where - N: ToString, - { - Activity::new(name.to_string(), ActivityType::Listening) + pub fn listening(name: impl Into) -> Activity { + Activity::new(name.into(), ActivityType::Listening) } /// Creates a [`Activity`] struct that appears as a `Watching ` status. @@ -220,16 +210,13 @@ impl Activity { /// #[command] /// async fn watch(ctx: &Context, _msg: &Message, args: Args) -> CommandResult { /// let name = args.message(); - /// ctx.set_activity(Activity::watching(&name)).await; + /// ctx.set_activity(Activity::watching(name)).await; /// /// Ok(()) /// } /// ``` - pub fn watching(name: N) -> Activity - where - N: ToString, - { - Activity::new(name.to_string(), ActivityType::Watching) + pub fn watching(name: impl Into) -> Activity { + Activity::new(name.into(), ActivityType::Watching) } /// Creates a [`Activity`] struct that appears as a `Competing in ` status. @@ -252,16 +239,13 @@ impl Activity { /// #[command] /// async fn compete(ctx: &Context, _msg: &Message, args: Args) -> CommandResult { /// let name = args.message(); - /// ctx.set_activity(Activity::competing(&name)).await; + /// ctx.set_activity(Activity::competing(name)).await; /// /// Ok(()) /// } /// ``` - pub fn competing(name: N) -> Activity - where - N: ToString, - { - Activity::new(name.to_string(), ActivityType::Competing) + pub fn competing(name: impl Into) -> Activity { + Activity::new(name.into(), ActivityType::Competing) } } diff --git a/src/model/mention.rs b/src/model/mention.rs index f8ab114ba20..54e835a5d09 100644 --- a/src/model/mention.rs +++ b/src/model/mention.rs @@ -38,7 +38,7 @@ pub trait Mentionable { /// to_channel /// .id /// .send_message(ctx, |m| { - /// m.content(format_args!( + /// m.content(format!( /// "Hi {member}, welcome to the server! \ /// Please refer to {rules} for our code of conduct, \ /// and enjoy your stay.", diff --git a/src/utils/custom_message.rs b/src/utils/custom_message.rs index ecb2c1a0c3e..3a865e2db3b 100644 --- a/src/utils/custom_message.rs +++ b/src/utils/custom_message.rs @@ -70,8 +70,8 @@ impl CustomMessage { /// /// If not used, the default value is an empty string (`String::default()`). #[inline] - pub fn content(&mut self, s: T) -> &mut Self { - self.msg.content = s.to_string(); + pub fn content(&mut self, s: impl Into) -> &mut Self { + self.msg.content = s.into(); self }