diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs index 554c06d309d..6ea945a02a1 100644 --- a/src/builder/create_embed.rs +++ b/src/builder/create_embed.rs @@ -19,10 +19,6 @@ use chrono::{DateTime, TimeZone}; use crate::internal::prelude::*; use crate::model::channel::Embed; use serde_json::{json, Value}; -use std::{ - default::Default, - fmt::Display -}; use crate::utils::{self, VecMap}; #[cfg(feature = "utils")] @@ -111,18 +107,11 @@ impl CreateEmbed { /// /// **Note**: This can't be longer than 2048 characters. #[inline] - pub fn description(&mut self, description: D) -> &mut Self { - self._description(description.to_string()); + pub fn description(&mut self, description: D) -> &mut Self { + self.0.insert("description", Value::String(description.to_string())); self } - fn _description(&mut self, description: String) { - self.0.insert( - "description", - Value::String(description), - ); - } - /// Set a field. Note that this will not overwrite other fields, and will /// add to them. /// @@ -130,12 +119,12 @@ impl CreateEmbed { /// name and 1024 in a field value. #[inline] pub fn field(&mut self, name: T, value: U, inline: bool) -> &mut Self - where T: Display, U: Display { - self._field(&name.to_string(), &value.to_string(), inline); + where T: ToString, U: ToString { + self._field(name.to_string(), value.to_string(), inline); self } - fn _field(&mut self, name: &str, value: &str, inline: bool) { + fn _field(&mut self, name: String, value: String, inline: bool) { { let entry = self.0 .entry("fields") @@ -158,11 +147,12 @@ impl CreateEmbed { /// [`field`]: #method.field pub fn fields(&mut self, fields: It) -> &mut Self where It: IntoIterator, - T: Display, - U: Display { - for field in fields { - self.field(field.0.to_string(), field.1.to_string(), field.2); + T: ToString, + U: ToString { + for (name, value, inline) in fields { + self.field(name, value, inline); } + self } @@ -183,9 +173,9 @@ impl CreateEmbed { self } - fn url_object(&mut self, name: &'static str, url: &str) -> &mut Self { + fn url_object(&mut self, name: &'static str, url: String) -> &mut Self { let obj = json!({ - "url": url.to_string() + "url": url, }); self.0.insert(name, obj); @@ -194,26 +184,19 @@ 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._image(url.as_ref()); - self - } + pub fn image(&mut self, url: S) -> &mut Self { + self.url_object("image", url.to_string()); - fn _image(&mut self, url: &str) { - 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._thumbnail(url.as_ref()); + pub fn thumbnail(&mut self, url: S) -> &mut Self { + self.url_object("thumbnail", url.to_string()); self } - fn _thumbnail(&mut self, url: &str) { - self.url_object("thumbnail", url); - } - /// Set the timestamp. /// /// You may pass a direct string: @@ -328,24 +311,16 @@ impl CreateEmbed { /// Set the title of the embed. #[inline] - pub fn title(&mut self, title: D) -> &mut Self { - self._title(title.to_string()); + pub fn title(&mut self, title: D) -> &mut Self { + self.0.insert("title", Value::String(title.to_string())); self } - fn _title(&mut self, title: String) { - self.0.insert("title", Value::String(title)); - } - /// Set the URL to direct to when clicking on the title. #[inline] - pub fn url>(&mut self, url: S) -> &mut Self { - self._url(url.as_ref()); - self - } - - fn _url(&mut self, url: &str) { + pub fn url(&mut self, url: S) -> &mut Self { self.0.insert("url", Value::String(url.to_string())); + self } /// Same as calling [`image`] with "attachment://filename.(jpg, png)". @@ -357,13 +332,10 @@ impl CreateEmbed { /// /// [`image`]: #method.image #[inline] - pub fn attachment>(&mut self, filename: S) -> &mut Self { - self._attachment(filename.as_ref()); - self - } + pub fn attachment(&mut self, filename: S) -> &mut Self { + self.image(format_args!("attachment://{}", filename)); - fn _attachment(&mut self, filename: &str) { - self.image(&format!("attachment://{}", filename)); + self } } @@ -458,19 +430,19 @@ pub struct CreateEmbedAuthor(pub VecMap<&'static str, Value>); impl CreateEmbedAuthor { /// Set the URL of the author's icon. - pub fn icon_url(&mut self, icon_url: &str) -> &mut Self { + pub fn icon_url(&mut self, icon_url: S) -> &mut Self { self.0.insert("icon_url", Value::String(icon_url.to_string())); self } /// Set the author's name. - pub fn name(&mut self, name: &str) -> &mut Self { + pub fn name(&mut self, name: S) -> &mut Self { self.0.insert("name", Value::String(name.to_string())); self } /// Set the author's URL. - pub fn url(&mut self, url: &str) -> &mut Self { + pub fn url(&mut self, url: S) -> &mut Self { self.0.insert("url", Value::String(url.to_string())); self } @@ -488,13 +460,13 @@ pub struct CreateEmbedFooter(pub VecMap<&'static str, Value>); impl CreateEmbedFooter { /// Set the icon URL's value. This only supports HTTP(S). - pub fn icon_url(&mut self, icon_url: &str) -> &mut Self { + pub fn icon_url(&mut self, icon_url: S) -> &mut Self { self.0.insert("icon_url", Value::String(icon_url.to_string())); self } /// Set the footer's text. - pub fn text(&mut self, text: D) -> &mut Self { + pub fn text(&mut self, text: S) -> &mut Self { self.0.insert("text", Value::String(text.to_string())); self } diff --git a/src/builder/create_invite.rs b/src/builder/create_invite.rs index abc3bdfa35b..2cc05915fe8 100644 --- a/src/builder/create_invite.rs +++ b/src/builder/create_invite.rs @@ -1,7 +1,6 @@ use crate::internal::prelude::*; use crate::utils::VecMap; use serde_json::Value; -use std::default::Default; /// A builder to create a [`RichInvite`] for use via [`GuildChannel::create_invite`]. /// diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs index 7fd3d217303..c9723814a44 100644 --- a/src/builder/create_message.rs +++ b/src/builder/create_message.rs @@ -1,7 +1,6 @@ use crate::internal::prelude::*; use crate::http::AttachmentType; use crate::model::channel::ReactionType; -use std::fmt::Display; use super::CreateEmbed; use crate::utils::{self, VecMap}; @@ -59,8 +58,8 @@ 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: D) -> &mut Self { + self.0.insert("content", Value::String(content.to_string())); self } diff --git a/src/builder/edit_channel.rs b/src/builder/edit_channel.rs index a9e8d796822..d1b94be4b44 100644 --- a/src/builder/edit_channel.rs +++ b/src/builder/edit_channel.rs @@ -36,7 +36,7 @@ impl EditChannel { /// The name of the channel. /// /// Must be between 2 and 100 characters long. - pub fn name(&mut self, name: &str) -> &mut Self { + pub fn name(&mut self, name: S) -> &mut Self { self.0.insert("name", Value::String(name.to_string())); self } @@ -54,7 +54,7 @@ impl EditChannel { /// This is for [text] channels only. /// /// [text]: ../model/channel/enum.ChannelType.html#variant.Text - pub fn topic(&mut self, topic: &str) -> &mut Self { + pub fn topic(&mut self, topic: S) -> &mut Self { self.0.insert("topic", Value::String(topic.to_string())); self } diff --git a/src/builder/edit_guild.rs b/src/builder/edit_guild.rs index eed61907e6f..a59498e173c 100644 --- a/src/builder/edit_guild.rs +++ b/src/builder/edit_guild.rs @@ -94,7 +94,7 @@ impl EditGuild { /// Set the name of the guild. /// /// **Note**: Must be between (and including) 2-100 chracters. - pub fn name(&mut self, name: &str) -> &mut Self { + pub fn name(&mut self, name: S) -> &mut Self { self.0.insert("name", Value::String(name.to_string())); self } diff --git a/src/builder/edit_member.rs b/src/builder/edit_member.rs index ed66f59fba5..29deb593be6 100644 --- a/src/builder/edit_member.rs +++ b/src/builder/edit_member.rs @@ -37,7 +37,7 @@ impl EditMember { /// Requires the [Manage Nicknames] permission. /// /// [Manage Nicknames]: ../model/permissions/struct.Permissions.html#associatedconstant.MANAGE_NICKNAMES - pub fn nickname(&mut self, nickname: &str) -> &mut Self { + pub fn nickname(&mut self, nickname: S) -> &mut Self { self.0.insert("nick", Value::String(nickname.to_string())); self } diff --git a/src/builder/edit_message.rs b/src/builder/edit_message.rs index 390f7a25aab..b49800c7103 100644 --- a/src/builder/edit_message.rs +++ b/src/builder/edit_message.rs @@ -1,5 +1,4 @@ use crate::internal::prelude::*; -use std::fmt::Display; use super::CreateEmbed; use crate::utils::{self, VecMap}; @@ -38,15 +37,11 @@ impl EditMessage { /// /// **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: D) -> &mut Self { + self.0.insert("content", Value::String(content.to_string())); self } - fn _content(&mut self, content: String) { - self.0.insert("content", Value::String(content)); - } - /// Set an embed for the message. pub fn embed(&mut self, f: F) -> &mut Self where F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed { diff --git a/src/builder/edit_profile.rs b/src/builder/edit_profile.rs index a26b77e89bc..289af112dad 100644 --- a/src/builder/edit_profile.rs +++ b/src/builder/edit_profile.rs @@ -100,7 +100,7 @@ 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: &str) -> &mut Self { + pub fn username(&mut self, username: S) -> &mut Self { self.0.insert("username", Value::String(username.to_string())); self } diff --git a/src/builder/edit_role.rs b/src/builder/edit_role.rs index d99417b42db..8470f860857 100644 --- a/src/builder/edit_role.rs +++ b/src/builder/edit_role.rs @@ -93,7 +93,7 @@ impl EditRole { } /// The name of the role to set. - pub fn name(&mut self, name: &str) -> &mut Self { + pub fn name(&mut self, name: S) -> &mut Self { self.0.insert("name", Value::String(name.to_string())); self } diff --git a/src/builder/execute_webhook.rs b/src/builder/execute_webhook.rs index eb33fa0645f..b050bfcd325 100644 --- a/src/builder/execute_webhook.rs +++ b/src/builder/execute_webhook.rs @@ -1,5 +1,4 @@ use serde_json::Value; -use std::default::Default; use crate::utils::VecMap; /// A builder to create the inner content of a [`Webhook`]'s execution. @@ -71,7 +70,7 @@ impl ExecuteWebhook { /// w.avatar_url(avatar_url).content("Here's a webhook") /// }); /// ``` - pub fn avatar_url(&mut self, avatar_url: &str) -> &mut Self { + pub fn avatar_url(&mut self, avatar_url: S) -> &mut Self { self.0.insert("avatar_url", Value::String(avatar_url.to_string())); self } @@ -102,7 +101,7 @@ impl ExecuteWebhook { /// ``` /// /// [`embeds`]: #method.embeds - pub fn content(&mut self, content: &str) -> &mut Self { + pub fn content(&mut self, content: S) -> &mut Self { self.0.insert("content", Value::String(content.to_string())); self } @@ -172,7 +171,7 @@ impl ExecuteWebhook { /// println!("Err sending webhook: {:?}", why); /// } /// ``` - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(&mut self, username: S) -> &mut Self { self.0.insert("username", Value::String(username.to_string())); self }