aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorPvdBerg <[email protected]>2018-05-27 19:57:23 -0700
committerPvdBerg <[email protected]>2018-05-27 19:57:23 -0700
commit67155c71af37c6e4056b153ab63a11424cf78334 (patch)
treed8d48f5875f53f2f7320c71e73b6b2061f619405 /src/utils
parentAdd Rich Presence parsing support (diff)
downloadserenity-67155c71af37c6e4056b153ab63a11424cf78334.tar.xz
serenity-67155c71af37c6e4056b153ab63a11424cf78334.zip
Make Message Builder use &mut self instead of self
This way the builder can be used where taking ownership is impractical.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/message_builder.rs86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs
index 93c5489..9e90c53 100644
--- a/src/utils/message_builder.rs
+++ b/src/utils/message_builder.rs
@@ -129,7 +129,7 @@ impl MessageBuilder {
/// [`ChannelId`]: ../model/id/struct.ChannelId.html
/// [`GuildChannel`]: ../model/channel/struct.GuildChannel.html
/// [Display implementation]: ../model/id/struct.ChannelId.html#method.fmt-1
- pub fn channel<C: Into<ChannelId>>(mut self, channel: C) -> Self {
+ pub fn channel<C: Into<ChannelId>>(&mut self, channel: C) -> &mut Self {
let _ = write!(self.0, "{}", channel.into().mention());
self
@@ -168,7 +168,7 @@ impl MessageBuilder {
/// ```
///
/// [Display implementation]: ../model/guild/struct.Emoji.html#method.fmt
- pub fn emoji(mut self, emoji: &Emoji) -> Self {
+ pub fn emoji(&mut self, emoji: &Emoji) -> &mut Self {
let _ = write!(self.0, "{}", emoji);
self
@@ -177,7 +177,7 @@ impl MessageBuilder {
/// Mentions something that implements the [`Mentionable`] trait.
///
/// [`Mentionable`]: ../model/misc/trait.Mentionable.html
- pub fn mention<M: Mentionable>(mut self, item: &M) -> Self {
+ pub fn mention<M: Mentionable>(&mut self, item: &M) -> &mut Self {
let _ = write!(self.0, "{}", item.mention());
self
@@ -198,7 +198,7 @@ impl MessageBuilder {
///
/// assert_eq!(message.push("ing").0, "testing");
/// ```
- pub fn push<D: I>(mut self, content: D) -> Self {
+ pub fn push<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str(&content.into().to_string());
self
@@ -243,7 +243,7 @@ impl MessageBuilder {
///
/// assert_eq!(content, "```\nhello\n```");
/// ```
- pub fn push_codeblock<D: I>(mut self, content: D, language: Option<&str>) -> Self {
+ pub fn push_codeblock<D: I>(&mut self, content: D, language: Option<&str>) -> &mut Self {
self.0.push_str("```");
if let Some(language) = language {
@@ -283,7 +283,7 @@ impl MessageBuilder {
///
/// assert_eq!(content, expected);
/// ```
- pub fn push_mono<D: I>(mut self, content: D) -> Self {
+ pub fn push_mono<D: I>(&mut self, content: D) -> &mut Self {
self.0.push('`');
self.0.push_str(&content.into().to_string());
self.0.push('`');
@@ -312,7 +312,7 @@ impl MessageBuilder {
///
/// assert_eq!(content, expected);
/// ```
- pub fn push_italic<D: I>(mut self, content: D) -> Self {
+ pub fn push_italic<D: I>(&mut self, content: D) -> &mut Self {
self.0.push('_');
self.0.push_str(&content.into().to_string());
self.0.push('_');
@@ -321,7 +321,7 @@ impl MessageBuilder {
}
/// Pushes an inline bold text to the content.
- pub fn push_bold<D: I>(mut self, content: D) -> Self {
+ pub fn push_bold<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str("**");
self.0.push_str(&content.into().to_string());
self.0.push_str("**");
@@ -330,7 +330,7 @@ impl MessageBuilder {
}
/// Pushes an underlined inline text to the content.
- pub fn push_underline<D: I>(mut self, content: D) -> Self {
+ pub fn push_underline<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str("__");
self.0.push_str(&content.into().to_string());
self.0.push_str("__");
@@ -339,7 +339,7 @@ impl MessageBuilder {
}
/// Pushes a strikethrough inline text to the content.
- pub fn push_strike<D: I>(mut self, content: D) -> Self {
+ pub fn push_strike<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str("~~");
self.0.push_str(&content.into().to_string());
self.0.push_str("~~");
@@ -360,8 +360,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "hello\nworld");
/// ```
- pub fn push_line<D: I>(mut self, content: D) -> Self {
- self = self.push(content);
+ pub fn push_line<D: I>(&mut self, content: D) -> &mut Self {
+ self.push(content);
self.0.push('\n');
self
@@ -380,8 +380,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "`hello`\nworld");
/// ```
- pub fn push_mono_line<D: I>(mut self, content: D) -> Self {
- self = self.push_mono(content);
+ pub fn push_mono_line<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_mono(content);
self.0.push('\n');
self
@@ -400,8 +400,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "_hello_\nworld");
/// ```
- pub fn push_italic_line<D: I>(mut self, content: D) -> Self {
- self = self.push_italic(content);
+ pub fn push_italic_line<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_italic(content);
self.0.push('\n');
self
@@ -420,8 +420,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "**hello**\nworld");
/// ```
- pub fn push_bold_line<D: I>(mut self, content: D) -> Self {
- self = self.push_bold(content);
+ pub fn push_bold_line<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_bold(content);
self.0.push('\n');
self
@@ -440,8 +440,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "__hello__\nworld");
/// ```
- pub fn push_underline_line<D: I>(mut self, content: D) -> Self {
- self = self.push_underline(content);
+ pub fn push_underline_line<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_underline(content);
self.0.push('\n');
self
@@ -460,8 +460,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "~~hello~~\nworld");
/// ```
- pub fn push_strike_line<D: I>(mut self, content: D) -> Self {
- self = self.push_strike(content);
+ pub fn push_strike_line<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_strike(content);
self.0.push('\n');
self
@@ -469,7 +469,7 @@ impl MessageBuilder {
/// Pushes text to your message, but normalizing content - that means
/// ensuring that there's no unwanted formatting, mention spam etc.
- pub fn push_safe<C: I>(mut self, content: C) -> Self {
+ pub fn push_safe<C: I>(&mut self, content: C) -> &mut Self {
{
let mut c = content.into();
c.inner = normalize(&c.inner)
@@ -484,7 +484,7 @@ impl MessageBuilder {
}
/// Pushes a code-block to your message normalizing content.
- pub fn push_codeblock_safe<D: I>(mut self, content: D, language: Option<&str>) -> Self {
+ pub fn push_codeblock_safe<D: I>(&mut self, content: D, language: Option<&str>) -> &mut Self {
self.0.push_str("```");
if let Some(language) = language {
@@ -502,7 +502,7 @@ impl MessageBuilder {
}
/// Pushes an inline monospaced text to the content normalizing content.
- pub fn push_mono_safe<D: I>(mut self, content: D) -> Self {
+ pub fn push_mono_safe<D: I>(&mut self, content: D) -> &mut Self {
self.0.push('`');
{
let mut c = content.into();
@@ -515,7 +515,7 @@ impl MessageBuilder {
}
/// Pushes an inline italicized text to the content normalizing content.
- pub fn push_italic_safe<D: I>(mut self, content: D) -> Self {
+ pub fn push_italic_safe<D: I>(&mut self, content: D) -> &mut Self {
self.0.push('_');
{
let mut c = content.into();
@@ -528,7 +528,7 @@ impl MessageBuilder {
}
/// Pushes an inline bold text to the content normalizing content.
- pub fn push_bold_safe<D: I>(mut self, content: D) -> Self {
+ pub fn push_bold_safe<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str("**");
{
let mut c = content.into();
@@ -541,7 +541,7 @@ impl MessageBuilder {
}
/// Pushes an underlined inline text to the content normalizing content.
- pub fn push_underline_safe<D: I>(mut self, content: D) -> Self {
+ pub fn push_underline_safe<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str("__");
{
let mut c = content.into();
@@ -554,7 +554,7 @@ impl MessageBuilder {
}
/// Pushes a strikethrough inline text to the content normalizing content.
- pub fn push_strike_safe<D: I>(mut self, content: D) -> Self {
+ pub fn push_strike_safe<D: I>(&mut self, content: D) -> &mut Self {
self.0.push_str("~~");
{
let mut c = content.into();
@@ -581,8 +581,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "Hello @\u{200B}everyone\nHow are you?");
/// ```
- pub fn push_line_safe<D: I>(mut self, content: D) -> Self {
- self = self.push_safe(content);
+ pub fn push_line_safe<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_safe(content);
self.0.push('\n');
self
@@ -603,8 +603,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "`'hello @\u{200B}everyone'`\nworld");
/// ```
- pub fn push_mono_line_safe<D: I>(mut self, content: D) -> Self {
- self = self.push_mono_safe(content);
+ pub fn push_mono_line_safe<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_mono_safe(content);
self.0.push('\n');
self
@@ -625,8 +625,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "_@\u{200B}everyone_\nIsn't a mention.");
/// ```
- pub fn push_italic_line_safe<D: I>(mut self, content: D) -> Self {
- self = self.push_italic_safe(content);
+ pub fn push_italic_line_safe<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_italic_safe(content);
self.0.push('\n');
self
@@ -647,8 +647,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "**@\u{200B}everyone**\nIsn't a mention.");
/// ```
- pub fn push_bold_line_safe<D: I>(mut self, content: D) -> Self {
- self = self.push_bold_safe(content);
+ pub fn push_bold_line_safe<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_bold_safe(content);
self.0.push('\n');
self
@@ -669,8 +669,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "__@\u{200B}everyone__\nIsn't a mention.");
/// ```
- pub fn push_underline_line_safe<D: I>(mut self, content: D) -> Self {
- self = self.push_underline_safe(content);
+ pub fn push_underline_line_safe<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_underline_safe(content);
self.0.push('\n');
self
@@ -692,8 +692,8 @@ impl MessageBuilder {
///
/// assert_eq!(content, "~~@\u{200B}everyone~~\nIsn't a mention.");
/// ```
- pub fn push_strike_line_safe<D: I>(mut self, content: D) -> Self {
- self = self.push_strike_safe(content);
+ pub fn push_strike_line_safe<D: I>(&mut self, content: D) -> &mut Self {
+ self.push_strike_safe(content);
self.0.push('\n');
self
@@ -710,7 +710,7 @@ impl MessageBuilder {
/// [`Role`]: ../model/guild/struct.Role.html
/// [`RoleId`]: ../model/id/struct.RoleId.html
/// [Display implementation]: ../model/id/struct.RoleId.html#method.fmt-1
- pub fn role<R: Into<RoleId>>(mut self, role: R) -> Self {
+ pub fn role<R: Into<RoleId>>(&mut self, role: R) -> &mut Self {
let _ = write!(self.0, "{}", role.into().mention());
self
@@ -727,7 +727,7 @@ impl MessageBuilder {
/// [`User`]: ../model/user/struct.User.html
/// [`UserId`]: ../model/id/struct.UserId.html
/// [Display implementation]: ../model/id/struct.UserId.html#method.fmt-1
- pub fn user<U: Into<UserId>>(mut self, user: U) -> Self {
+ pub fn user<U: Into<UserId>>(&mut self, user: U) -> &mut Self {
let _ = write!(self.0, "{}", user.into().mention());
self