diff options
| author | acdenisSK <[email protected]> | 2017-08-04 20:57:49 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-08-04 20:59:42 +0200 |
| commit | 1b1104d3a458aefe109f63e5a18c71e3db087a27 (patch) | |
| tree | 00fa21180c1af8bab60c01c9099be83c292cc3e8 /src | |
| parent | Deprecate `GuildId::as_channel_id` and add simulation methods for the "defaul... (diff) | |
| download | serenity-1b1104d3a458aefe109f63e5a18c71e3db087a27.tar.xz serenity-1b1104d3a458aefe109f63e5a18c71e3db087a27.zip | |
Refactor the display stuff a bit
Diffstat (limited to 'src')
| -rw-r--r-- | src/builder/create_embed.rs | 23 | ||||
| -rw-r--r-- | src/builder/create_message.rs | 5 | ||||
| -rw-r--r-- | src/utils/message_builder.rs | 69 |
3 files changed, 22 insertions, 75 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs index 01c3323..2dc9dc4 100644 --- a/src/builder/create_embed.rs +++ b/src/builder/create_embed.rs @@ -97,11 +97,9 @@ impl CreateEmbed { /// /// **Note**: This can't be longer than 2048 characters. pub fn description<D: Display>(mut self, description: D) -> Self { - let mut s = "".to_owned(); - let _ = writeln!(&mut s, "{}", description); self.0.insert( "description".to_owned(), - Value::String(s), + Value::String(format!("{}", description)), ); CreateEmbed(self.0) @@ -292,10 +290,8 @@ impl CreateEmbed { /// Set the title of the embed. pub fn title<D: Display>(mut self, title: D) -> Self { - let mut s = "".to_owned(); - let _ = writeln!(&mut s, "{}", title); self.0 - .insert("title".to_owned(), Value::String(s)); + .insert("title".to_owned(), Value::String(format!("{}", title))); CreateEmbed(self.0) } @@ -444,22 +440,16 @@ impl CreateEmbedField { /// Set the field's name. It can't be longer than 256 characters. pub fn name<D: Display>(mut self, name: D) -> Self { - let mut s = "".to_owned(); - let _ = writeln!(&mut s, "{}", name); - self.0 - .insert("name".to_owned(), Value::String(s)); + .insert("name".to_owned(), Value::String(format!("{}", name))); self } /// Set the field's value. It can't be longer than 1024 characters. pub fn value<D: Display>(mut self, value: D) -> Self { - let mut s = "".to_owned(); - let _ = writeln!(&mut s, "{}", value); - self.0 - .insert("value".to_owned(), Value::String(s)); + .insert("value".to_owned(), Value::String(format!("{}", value))); self } @@ -497,11 +487,8 @@ impl CreateEmbedFooter { /// Set the footer's text. pub fn text<D: Display>(mut self, text: D) -> Self { - let mut s = "".to_owned(); - let _ = writeln!(&mut s, "{}", text); - self.0 - .insert("text".to_owned(), Value::String(s)); + .insert("text".to_owned(), Value::String(format!("{}", text))); self } diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs index 63743cd..835b816 100644 --- a/src/builder/create_message.rs +++ b/src/builder/create_message.rs @@ -46,11 +46,8 @@ impl CreateMessage { /// /// **Note**: Message contents must be under 2000 unicode code points. pub fn content<D: Display>(mut self, content: D) -> Self { - let mut s = "".to_owned(); - let _ = writeln!(&mut s, "{}", content); - self.0 - .insert("content".to_owned(), Value::String(s)); + .insert("content".to_owned(), Value::String(format!("{}", content))); CreateMessage(self.0, self.1) } diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs index 2801f4b..ee30678 100644 --- a/src/utils/message_builder.rs +++ b/src/utils/message_builder.rs @@ -190,9 +190,7 @@ impl MessageBuilder { /// assert_eq!(message.push("ing").0, "testing"); /// ``` pub fn push<D: fmt::Display>(mut self, content: D) -> Self { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); + let _ = write!(self.0, "{}", content); self } @@ -240,17 +238,11 @@ impl MessageBuilder { self.0.push_str("```"); if let Some(language) = language { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", language); - self.0.push_str(&s); + let _ = write!(self.0, "{}", language); } self.0.push('\n'); - { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); - } + let _ = write!(self.0, "{}", content); self.0.push_str("\n```"); self @@ -284,11 +276,7 @@ impl MessageBuilder { /// ``` pub fn push_mono<D: fmt::Display>(mut self, content: D) -> Self { self.0.push('`'); - { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); - } + let _ = write!(self.0, "{}", content); self.0.push('`'); self @@ -317,11 +305,7 @@ impl MessageBuilder { /// ``` pub fn push_italic<D: fmt::Display>(mut self, content: D) -> Self { self.0.push('_'); - { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); - } + let _ = write!(self.0, "{}", content); self.0.push('_'); self @@ -330,11 +314,7 @@ impl MessageBuilder { /// Pushes an inline bold text to the content. pub fn push_bold<D: fmt::Display>(mut self, content: D) -> Self { self.0.push_str("**"); - { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); - } + let _ = write!(self.0, "{}", content); self.0.push_str("**"); self @@ -343,11 +323,7 @@ impl MessageBuilder { /// Pushes an underlined inline text to the content. pub fn push_underline<D: fmt::Display>(mut self, content: D) -> Self { self.0.push_str("__"); - { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); - } + let _ = write!(self.0, "{}", content); self.0.push_str("__"); self @@ -356,11 +332,7 @@ impl MessageBuilder { /// Pushes a strikethrough inline text to the content. pub fn push_strike<D: fmt::Display>(mut self, content: D) -> Self { self.0.push_str("~~"); - { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); - self.0.push_str(&s); - } + let _ = write!(self.0, "{}", content); self.0.push_str("~~"); self @@ -490,8 +462,7 @@ impl MessageBuilder { /// ensuring that there's no unwanted formatting, mention spam etc. pub fn push_safe<D: fmt::Display>(mut self, content: D) -> Self { { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s) .replace('*', "\\=*") .replace('`', "\\`") @@ -508,15 +479,12 @@ impl MessageBuilder { self.0.push_str("```"); if let Some(language) = language { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", language); - self.0.push_str(&s); + let _ = write!(self.0, "{}", language); } self.0.push('\n'); { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s).replace("```", "'''"); self.0.push_str(&s); } @@ -529,8 +497,7 @@ impl MessageBuilder { pub fn push_mono_safe<D: fmt::Display>(mut self, content: D) -> Self { self.0.push('`'); { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s).replace('`', "'"); self.0.push_str(&s); } @@ -543,8 +510,7 @@ impl MessageBuilder { pub fn push_italic_safe<D: fmt::Display>(mut self, content: D) -> Self { self.0.push('_'); { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s).replace('_', " "); self.0.push_str(&s); } @@ -557,8 +523,7 @@ impl MessageBuilder { pub fn push_bold_safe<D: fmt::Display>(mut self, content: D) -> Self { self.0.push_str("**"); { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s).replace("**", " "); self.0.push_str(&s); } @@ -571,8 +536,7 @@ impl MessageBuilder { pub fn push_underline_safe<D: fmt::Display>(mut self, content: D) -> Self { self.0.push_str("__"); { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s).replace("__", " "); self.0.push_str(&s); } @@ -585,8 +549,7 @@ impl MessageBuilder { pub fn push_strike_safe<D: fmt::Display>(mut self, content: D) -> Self { self.0.push_str("~~"); { - let mut s = "".to_string(); - let _ = write!(&mut s, "{}", content); + let mut s = format!("{}", content); s = normalize(&s).replace("~~", " "); self.0.push_str(&s); } |