aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-04-26 21:02:02 -0700
committerZeyla Hellyer <[email protected]>2018-05-27 19:21:18 -0700
commit309eee7ba66de7870011825a9130828e9b49e83c (patch)
tree202559d698f927b0f8840804b7b5ccc83cb325f0 /src
parentRemove user account relation docs/functions (diff)
downloadserenity-309eee7ba66de7870011825a9130828e9b49e83c.tar.xz
serenity-309eee7ba66de7870011825a9130828e9b49e83c.zip
Make builders mutably borrowed
Change the builders so that they are now mutably borrowed, accepting `&mut self` instead of `self`. Their methods now return `()` instead of `Self`. Upgrade path: Change code such as the following: ```rust channel.send_message(|m| m .embed(|e| e .description("test") .title("title"))); ``` to the following style: ```rust channel.send_message(|mut m| { m.embed(|mut e| { e.description("test"); e.title("title"); e }); m }); ``` Closes #159.
Diffstat (limited to 'src')
-rw-r--r--src/builder/create_embed.rs170
-rw-r--r--src/builder/create_invite.rs49
-rw-r--r--src/builder/create_message.rs48
-rw-r--r--src/builder/edit_channel.rs26
-rw-r--r--src/builder/edit_guild.rs60
-rw-r--r--src/builder/edit_member.rs21
-rw-r--r--src/builder/edit_message.rs14
-rw-r--r--src/builder/edit_profile.rs23
-rw-r--r--src/builder/edit_role.rs43
-rw-r--r--src/builder/execute_webhook.rs90
-rw-r--r--src/builder/get_messages.rs33
-rw-r--r--src/client/context.rs6
-rw-r--r--src/framework/standard/help_commands.rs72
-rw-r--r--src/model/channel/channel_id.rs18
-rw-r--r--src/model/channel/embed.rs11
-rw-r--r--src/model/channel/guild_channel.rs7
-rw-r--r--src/model/channel/message.rs4
-rw-r--r--src/model/guild/member.rs6
-rw-r--r--src/model/guild/role.rs6
-rw-r--r--src/model/user.rs8
-rw-r--r--src/model/webhook.rs35
21 files changed, 389 insertions, 361 deletions
diff --git a/src/builder/create_embed.rs b/src/builder/create_embed.rs
index 1781225..0bc3638 100644
--- a/src/builder/create_embed.rs
+++ b/src/builder/create_embed.rs
@@ -49,13 +49,11 @@ impl CreateEmbed {
/// information.
///
/// [`CreateEmbedAuthor`]: struct.CreateEmbedAuthor.html
- pub fn author<F>(mut self, f: F) -> Self
+ pub fn author<F>(&mut self, f: F)
where F: FnOnce(CreateEmbedAuthor) -> CreateEmbedAuthor {
let map = utils::vecmap_to_json_map(f(CreateEmbedAuthor::default()).0);
self.0.insert("author", Value::Object(map));
-
- self
}
/// Set the colour of the left-hand side of the embed.
@@ -65,17 +63,17 @@ impl CreateEmbed {
/// [`colour`]: #method.colour
#[cfg(feature = "utils")]
#[inline]
- pub fn color<C: Into<Colour>>(self, colour: C) -> Self { self.colour(colour.into()) }
+ pub fn color<C: Into<Colour>>(&mut self, colour: C) {
+ self.colour(colour.into())
+ }
/// Set the colour of the left-hand side of the embed.
#[cfg(feature = "utils")]
- pub fn colour<C: Into<Colour>>(mut self, colour: C) -> Self {
+ pub fn colour<C: Into<Colour>>(&mut self, colour: C) {
self.0.insert(
"color",
Value::Number(Number::from(u64::from(colour.into().0))),
);
-
- self
}
/// Set the colour of the left-hand side of the embed.
@@ -85,27 +83,22 @@ impl CreateEmbed {
/// [`colour`]: #method.colour
#[cfg(not(feature = "utils"))]
#[inline]
- pub fn color(self, colour: u32) -> Self { self.colour(colour) }
+ pub fn color(self, colour: u32) { self.colour(colour) }
/// Set the colour of the left-hand side of the embed.
#[cfg(not(feature = "utils"))]
- pub fn colour(mut self, colour: u32) -> Self {
- self.0
- .insert("color", Value::Number(Number::from(colour)));
-
- self
+ pub fn colour(&mut self, colour: u32) {
+ self.0.insert("color", Value::Number(Number::from(colour)));
}
/// Set the description of the embed.
///
/// **Note**: This can't be longer than 2048 characters.
- pub fn description<D: Display>(mut self, description: D) -> Self {
+ pub fn description<D: Display>(&mut self, description: D) {
self.0.insert(
"description",
Value::String(description.to_string()),
);
-
- self
}
/// Set a field. Note that this will not overwrite other fields, and will
@@ -118,7 +111,7 @@ impl CreateEmbed {
/// name and 1024 in a field value and a field is inline by default.
///
/// [`CreateEmbedField`]: struct.CreateEmbedField.html
- pub fn field<T, U>(mut self, name: T, value: U, inline: bool) -> Self
+ pub fn field<T, U>(&mut self, name: T, value: U, inline: bool)
where T: Display, U: Display {
{
let entry = self.0
@@ -133,20 +126,16 @@ impl CreateEmbed {
}));
}
}
-
- self
}
/// Adds multiple fields at once.
- pub fn fields<T, U, It>(mut self, fields: It) -> Self
+ pub fn fields<T, U, It>(&mut self, fields: It)
where It: IntoIterator<Item=(T, U, bool)>,
T: Display,
U: Display {
for field in fields {
- self = self.field(field.0.to_string(), field.1.to_string(), field.2);
+ self.field(field.0.to_string(), field.1.to_string(), field.2);
}
-
- self
}
/// Set the footer of the embed.
@@ -155,36 +144,32 @@ impl CreateEmbed {
/// information.
///
/// [`CreateEmbedFooter`]: struct.CreateEmbedFooter.html
- pub fn footer<F>(mut self, f: F) -> Self
+ pub fn footer<F>(&mut self, f: F)
where F: FnOnce(CreateEmbedFooter) -> CreateEmbedFooter {
let footer = f(CreateEmbedFooter::default()).0;
let map = utils::vecmap_to_json_map(footer);
self.0.insert("footer", Value::Object(map));
-
- self
}
- fn url_object(mut self, name: &'static str, url: &str) -> Self {
+ fn url_object(&mut self, name: &'static str, url: &str) {
let obj = json!({
"url": url.to_string()
});
self.0.insert(name, obj);
-
- self
}
/// Set the image associated with the embed. This only supports HTTP(S).
#[inline]
- pub fn image<S: AsRef<str>>(self, url: S) -> Self {
- self.url_object("image", url.as_ref())
+ pub fn image<S: AsRef<str>>(&mut self, url: S) {
+ self.url_object("image", url.as_ref());
}
/// Set the thumbnail of the embed. This only supports HTTP(S).
#[inline]
- pub fn thumbnail<S: AsRef<str>>(self, url: S) -> Self {
- self.url_object("thumbnail", url.as_ref())
+ pub fn thumbnail<S: AsRef<str>>(&mut self, url: S) {
+ self.url_object("thumbnail", url.as_ref());
}
/// Set the timestamp.
@@ -212,10 +197,16 @@ impl CreateEmbed {
/// impl EventHandler for Handler {
/// fn message(&self, _: Context, msg: Message) {
/// if msg.content == "~embed" {
- /// let _ = msg.channel_id.send_message(|m| m
- /// .embed(|e| e
- /// .title("hello")
- /// .timestamp("2004-06-08T16:04:23")));
+ /// let _ = msg.channel_id.send_message(|mut m| {
+ /// m.embed(|mut e| {
+ /// e.title("hello");
+ /// e.timestamp("2004-06-08T16:04:23");
+ ///
+ /// e
+ /// });
+ ///
+ /// m
+ /// });
/// }
/// }
/// }
@@ -252,18 +243,25 @@ impl CreateEmbed {
/// if let Some(channel) = channel_search {
/// let user = member.user.read();
///
- /// let _ = channel.read().send_message(|m| m
- /// .embed(|e| {
- /// let mut e = e
- /// .author(|a| a.icon_url(&user.face()).name(&user.name))
- /// .title("Member Join");
+ /// let _ = channel.read().send_message(|mut m| {
+ /// m.embed(|mut e| {
+ /// e.author(|mut a| {
+ /// a.icon_url(&user.face());
+ /// a.name(&user.name);
+ ///
+ /// a
+ /// });
+ /// e.title("Member Join");
///
/// if let Some(ref joined_at) = member.joined_at {
- /// e = e.timestamp(joined_at);
+ /// e.timestamp(joined_at);
/// }
///
/// e
- /// }));
+ /// });
+ ///
+ /// m
+ /// });
/// }
/// }
/// }
@@ -273,27 +271,18 @@ impl CreateEmbed {
///
/// client.start().unwrap();
/// ```
- pub fn timestamp<T: Into<Timestamp>>(mut self, timestamp: T) -> Self {
- self.0
- .insert("timestamp", Value::String(timestamp.into().ts));
-
- self
+ pub fn timestamp<T: Into<Timestamp>>(&mut self, timestamp: T) {
+ self.0.insert("timestamp", Value::String(timestamp.into().ts));
}
/// Set the title of the embed.
- pub fn title<D: Display>(mut self, title: D) -> Self {
- self.0
- .insert("title", Value::String(title.to_string()));
-
- self
+ pub fn title<D: Display>(&mut self, title: D) {
+ self.0.insert("title", Value::String(title.to_string()));
}
/// Set the URL to direct to when clicking on the title.
- pub fn url<S: AsRef<str>>(mut self, url: S) -> Self {
- self.0
- .insert("url", Value::String(url.as_ref().to_string()));
-
- self
+ pub fn url<S: AsRef<str>>(&mut self, url: S) {
+ self.0.insert("url", Value::String(url.as_ref().to_string()));
}
/// Same as calling [`image`] with "attachment://filename.(jpg, png)".
@@ -302,7 +291,7 @@ impl CreateEmbed {
/// with the provided filename. Or else this won't work.
///
/// [`ChannelId::send_files`]: ../model/id/struct.ChannelId.html#send_files
- pub fn attachment<S: AsRef<str>>(self, filename: S) -> Self {
+ pub fn attachment<S: AsRef<str>>(&mut self, filename: S) {
self.image(&format!("attachment://{}", filename.as_ref()))
}
}
@@ -321,19 +310,20 @@ impl From<Embed> for CreateEmbed {
/// Converts the fields of an embed into the values for a new embed builder.
///
/// Some values - such as Proxy URLs - are not preserved.
- fn from(embed: Embed) -> CreateEmbed {
- let mut b = CreateEmbed::default().colour(embed.colour);
+ fn from(embed: Embed) -> Self {
+ let mut b = CreateEmbed::default();
+ b.colour(embed.colour);
if let Some(author) = embed.author {
- b = b.author(move |mut a| {
- a = a.name(&author.name);
+ b.author(move |mut a| {
+ a.name(&author.name);
if let Some(icon_url) = author.icon_url {
- a = a.icon_url(&icon_url);
+ a.icon_url(&icon_url);
}
if let Some(url) = author.url {
- a = a.url(&url);
+ a.url(&url);
}
a
@@ -341,39 +331,39 @@ impl From<Embed> for CreateEmbed {
}
if let Some(description) = embed.description {
- b = b.description(&description);
+ b.description(&description);
}
for field in embed.fields {
- b = b.field(field.name, field.value, field.inline);
+ b.field(field.name, field.value, field.inline);
}
if let Some(image) = embed.image {
- b = b.image(&image.url);
+ b.image(&image.url);
}
if let Some(timestamp) = embed.timestamp {
- b = b.timestamp(timestamp);
+ b.timestamp(timestamp);
}
if let Some(thumbnail) = embed.thumbnail {
- b = b.thumbnail(&thumbnail.url);
+ b.thumbnail(&thumbnail.url);
}
if let Some(url) = embed.url {
- b = b.url(&url);
+ b.url(&url);
}
if let Some(title) = embed.title {
- b = b.title(&title);
+ b.title(&title);
}
if let Some(footer) = embed.footer {
- b = b.footer(move |mut f| {
- f = f.text(&footer.text);
+ b.footer(move |mut f| {
+ f.text(&footer.text);
if let Some(icon_url) = footer.icon_url {
- f = f.icon_url(&icon_url);
+ f.icon_url(&icon_url);
}
f
@@ -397,24 +387,18 @@ 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) -> Self {
+ pub fn icon_url(&mut self, icon_url: &str) {
self.0.insert("icon_url", Value::String(icon_url.to_string()));
-
- self
}
/// Set the author's name.
- pub fn name(mut self, name: &str) -> Self {
+ pub fn name(&mut self, name: &str) {
self.0.insert("name", Value::String(name.to_string()));
-
- self
}
/// Set the author's URL.
- pub fn url(mut self, url: &str) -> Self {
+ pub fn url(&mut self, url: &str) {
self.0.insert("url", Value::String(url.to_string()));
-
- self
}
}
@@ -430,17 +414,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) -> Self {
+ pub fn icon_url(&mut self, icon_url: &str) {
self.0.insert("icon_url", Value::String(icon_url.to_string()));
-
- self
}
/// Set the footer's text.
- pub fn text<D: Display>(mut self, text: D) -> Self {
+ pub fn text<D: Display>(&mut self, text: D) {
self.0.insert("text", Value::String(text.to_string()));
-
- self
}
}
@@ -451,15 +431,15 @@ pub struct Timestamp {
impl From<String> for Timestamp {
fn from(ts: String) -> Self {
- Timestamp {
- ts,
+ Self {
+ ts: ts,
}
}
}
impl<'a> From<&'a str> for Timestamp {
fn from(ts: &'a str) -> Self {
- Timestamp {
+ Self {
ts: ts.to_string(),
}
}
@@ -468,7 +448,7 @@ impl<'a> From<&'a str> for Timestamp {
impl<'a, Tz: TimeZone> From<&'a DateTime<Tz>> for Timestamp
where Tz::Offset: Display {
fn from(dt: &'a DateTime<Tz>) -> Self {
- Timestamp {
+ Self {
ts: dt.to_rfc3339(),
}
}
diff --git a/src/builder/create_invite.rs b/src/builder/create_invite.rs
index c9b00ff..59bb5e9 100644
--- a/src/builder/create_invite.rs
+++ b/src/builder/create_invite.rs
@@ -33,7 +33,14 @@ use utils::VecMap;
///
/// let reader = channel.read();
///
-/// let invite = match reader.create_invite(|i| i.max_age(3600).max_uses(10)) {
+/// let creation = reader.create_invite(|mut i| {
+/// i.max_age(3600);
+/// i.max_uses(10);
+///
+/// i
+/// });
+///
+/// let invite = match creation {
/// Ok(invite) => invite,
/// Err(why) => {
/// println!("Err creating invite: {:?}", why);
@@ -84,7 +91,11 @@ impl CreateInvite {
/// # let channel = CACHE.read().guild_channel(81384788765712384).unwrap();
/// # let channel = channel.read();
/// #
- /// let invite = channel.create_invite(|i| i.max_age(3600))?;
+ /// let invite = channel.create_invite(|mut i| {
+ /// i.max_age(3600);
+ ///
+ /// i
+ /// })?;
/// # Ok(())
/// # }
/// #
@@ -92,10 +103,8 @@ impl CreateInvite {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn max_age(mut self, max_age: u64) -> Self {
+ pub fn max_age(&mut self, max_age: u64) {
self.0.insert("max_age", Value::Number(Number::from(max_age)));
-
- self
}
/// The number of uses that the invite will be valid for.
@@ -117,7 +126,11 @@ impl CreateInvite {
/// # let channel = CACHE.read().guild_channel(81384788765712384).unwrap();
/// # let channel = channel.read();
/// #
- /// let invite = channel.create_invite(|i| i.max_uses(5))?;
+ /// let invite = channel.create_invite(|mut i| {
+ /// i.max_uses(5);
+ ///
+ /// i
+ /// })?;
/// # Ok(())
/// # }
/// #
@@ -125,10 +138,8 @@ impl CreateInvite {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn max_uses(mut self, max_uses: u64) -> Self {
+ pub fn max_uses(&mut self, max_uses: u64) {
self.0.insert("max_uses", Value::Number(Number::from(max_uses)));
-
- self
}
/// Whether an invite grants a temporary membership.
@@ -148,7 +159,11 @@ impl CreateInvite {
/// # let channel = CACHE.read().guild_channel(81384788765712384).unwrap();
/// # let channel = channel.read();
/// #
- /// let invite = channel.create_invite(|i| i.temporary(true))?;
+ /// let invite = channel.create_invite(|mut i| {
+ /// i.temporary(true);
+ ///
+ /// i
+ /// })?;
/// # Ok(())
/// # }
/// #
@@ -156,10 +171,8 @@ impl CreateInvite {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn temporary(mut self, temporary: bool) -> Self {
+ pub fn temporary(&mut self, temporary: bool) {
self.0.insert("temporary", Value::Bool(temporary));
-
- self
}
/// Whether or not to try to reuse a similar invite.
@@ -179,7 +192,11 @@ impl CreateInvite {
/// # let channel = CACHE.read().guild_channel(81384788765712384).unwrap();
/// # let channel = channel.read();
/// #
- /// let invite = channel.create_invite(|i| i.unique(true))?;
+ /// let invite = channel.create_invite(|mut i| {
+ /// i.unique(true);
+ ///
+ /// i
+ /// })?;
/// # Ok(())
/// # }
/// #
@@ -187,10 +204,8 @@ impl CreateInvite {
/// # try_main().unwrap();
/// # }
/// ```
- pub fn unique(mut self, unique: bool) -> Self {
+ pub fn unique(&mut self, unique: bool) {
self.0.insert("unique", Value::Bool(unique));
-
- self
}
}
diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs
index c650b9e..b75c5eb 100644
--- a/src/builder/create_message.rs
+++ b/src/builder/create_message.rs
@@ -27,12 +27,19 @@ use utils::{self, VecMap};
///
/// let channel_id = ChannelId(7);
///
-/// let _ = channel_id.send_message(|m| m
-/// .content("test")
-/// .tts(true)
-/// .embed(|e| e
-/// .title("This is an embed")
-/// .description("With a description")));
+/// let _ = channel_id.send_message(|mut m| {
+/// m.content("test");
+/// m.tts(true);
+///
+/// m.embed(|mut e| {
+/// e.title("This is an embed");
+/// e.description("With a description");
+///
+/// e
+/// });
+///
+/// m
+/// });
/// ```
///
/// [`ChannelId::say`]: ../model/id/struct.ChannelId.html#method.say
@@ -47,21 +54,16 @@ impl<'a> CreateMessage<'a> {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
- pub fn content<D: Display>(mut self, content: D) -> Self {
+ pub fn content<D: Display>(&mut self, content: D) {
self.0.insert("content", Value::String(content.to_string()));
-
- CreateMessage(self.0, self.1, self.2)
}
/// Set an embed for the message.
- pub fn embed<F>(mut self, f: F) -> Self
- where F: FnOnce(CreateEmbed) -> CreateEmbed {
+ pub fn embed<F: FnOnce(CreateEmbed) -> CreateEmbed>(&mut self, f: F) {
let map = utils::vecmap_to_json_map(f(CreateEmbed::default()).0);
let embed = Value::Object(map);
self.0.insert("embed", embed);
-
- CreateMessage(self.0, self.1, self.2)
}
/// Set whether the message is text-to-speech.
@@ -69,41 +71,31 @@ impl<'a> CreateMessage<'a> {
/// Think carefully before setting this to `true`.
///
/// Defaults to `false`.
- pub fn tts(mut self, tts: bool) -> Self {
+ pub fn tts(&mut self, tts: bool) {
self.0.insert("tts", Value::Bool(tts));
-
- CreateMessage(self.0, self.1, self.2)
}
/// Adds a list of reactions to create after the message's sent.
- pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item=R>>(mut self, reactions: It) -> Self {
+ pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item=R>>(&mut self, reactions: It) {
self.1 = Some(reactions.into_iter().map(|r| r.into()).collect());
-
- CreateMessage(self.0, self.1, self.2)
}
/// Appends a file to the message.
- pub fn add_file<T: Into<AttachmentType<'a>>>(mut self, file: T) -> Self {
+ pub fn add_file<T: Into<AttachmentType<'a>>>(&mut self, file: T) {
self.2.push(file.into());
-
- CreateMessage(self.0, self.1, self.2)
}
/// Appends a list of files to the message.
- pub fn add_files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item=T>>(mut self, files: It) -> Self {
+ pub fn add_files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item=T>>(&mut self, files: It) {
self.2.extend(files.into_iter().map(|f| f.into()));
-
- CreateMessage(self.0, self.1, self.2)
}
/// Sets a list of files to include in the message.
///
/// Calling this multiple times will overwrite the file list.
/// To append files, call `add_file` or `add_files` instead.
- pub fn files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item=T>>(mut self, files: It) -> Self {
+ pub fn files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item=T>>(&mut self, files: It) {
self.2 = files.into_iter().map(|f| f.into()).collect();
-
- CreateMessage(self.0, self.1, self.2)
}
}
diff --git a/src/builder/edit_channel.rs b/src/builder/edit_channel.rs
index b8d897b..7c30631 100644
--- a/src/builder/edit_channel.rs
+++ b/src/builder/edit_channel.rs
@@ -28,26 +28,20 @@ impl EditChannel {
/// This is for [voice] channels only.
///
/// [voice]: ../model/channel/enum.ChannelType.html#variant.Voice
- pub fn bitrate(mut self, bitrate: u64) -> Self {
+ pub fn bitrate(&mut self, bitrate: u64) {
self.0.insert("bitrate", Value::Number(Number::from(bitrate)));
-
- self
}
/// The name of the channel.
///
/// Must be between 2 and 100 characters long.
- pub fn name(mut self, name: &str) -> Self {
+ pub fn name(&mut self, name: &str) {
self.0.insert("name", Value::String(name.to_string()));
-
- self
}
/// The position of the channel in the channel list.
- pub fn position(mut self, position: u64) -> Self {
+ pub fn position(&mut self, position: u64) {
self.0.insert("position", Value::Number(Number::from(position)));
-
- self
}
/// The topic of the channel. Can be empty.
@@ -57,10 +51,8 @@ impl EditChannel {
/// This is for [text] channels only.
///
/// [text]: ../model/channel/enum.ChannelType.html#variant.Text
- pub fn topic(mut self, topic: &str) -> Self {
+ pub fn topic(&mut self, topic: &str) {
self.0.insert("topic", Value::String(topic.to_string()));
-
- self
}
/// The number of users that may be in the channel simultaneously.
@@ -68,10 +60,8 @@ impl EditChannel {
/// This is for [voice] channels only.
///
/// [voice]: ../model/channel/enum.ChannelType.html#variant.Voice
- pub fn user_limit(mut self, user_limit: u64) -> Self {
+ pub fn user_limit(&mut self, user_limit: u64) {
self.0.insert("user_limit", Value::Number(Number::from(user_limit)));
-
- self
}
/// The parent category of the channel.
@@ -80,14 +70,12 @@ impl EditChannel {
///
/// [text]: ../model/channel/enum.ChannelType.html#variant.Text
/// [voice]: ../model/channel/enum.ChannelType.html#variant.Voice
- pub fn category<C>(mut self, category: C) -> Self
- where C: Into<Option<ChannelId>> {
+ pub fn category<C: Into<Option<ChannelId>>>(&mut self, category: C) {
let parent_id = match category.into() {
Some(c) => Value::Number(Number::from(c.0)),
None => Value::Null
};
- self.0.insert("parent_id", parent_id);
- self
+ self.0.insert("parent_id", parent_id);
}
}
diff --git a/src/builder/edit_guild.rs b/src/builder/edit_guild.rs
index c24b9b4..8c7765b 100644
--- a/src/builder/edit_guild.rs
+++ b/src/builder/edit_guild.rs
@@ -23,7 +23,7 @@ impl EditGuild {
/// valid.
///
/// [`afk_timeout`]: #method.afk_timeout
- pub fn afk_channel<C: Into<ChannelId>>(mut self, channel: Option<C>) -> Self {
+ pub fn afk_channel<C: Into<ChannelId>>(&mut self, channel: Option<C>) {
self.0.insert(
"afk_channel_id",
match channel {
@@ -31,21 +31,17 @@ impl EditGuild {
None => Value::Null,
},
);
-
- self
}
/// Set the amount of time a user is to be moved to the AFK channel -
/// configured via [`afk_channel`] - after being AFK.
///
/// [`afk_channel`]: #method.afk_channel
- pub fn afk_timeout(mut self, timeout: u64) -> Self {
+ pub fn afk_timeout(&mut self, timeout: u64) {
self.0.insert(
"afk_timeout",
Value::Number(Number::from(timeout)),
);
-
- self
}
/// Set the icon of the guild. Pass `None` to remove the icon.
@@ -67,7 +63,11 @@ impl EditGuild {
///
/// let base64_icon = utils::read_image("./guild_icon.png")?;
///
- /// guild.edit(|g| g.icon(Some(&base64_icon)))?;
+ /// guild.edit(|mut g| {
+ /// g.icon(Some(&base64_icon));
+ ///
+ /// g
+ /// })?;
/// # Ok(())
/// # }
/// #
@@ -77,32 +77,26 @@ impl EditGuild {
/// ```
///
/// [`utils::read_image`]: ../utils/fn.read_image.html
- pub fn icon(mut self, icon: Option<&str>) -> Self {
+ pub fn icon(&mut self, icon: Option<&str>) {
self.0.insert(
"icon",
icon.map_or_else(|| Value::Null, |x| Value::String(x.to_string())),
);
-
- self
}
/// Set the name of the guild.
///
/// **Note**: Must be between (and including) 2-100 chracters.
- pub fn name(mut self, name: &str) -> Self {
+ pub fn name(&mut self, name: &str) {
self.0.insert("name", Value::String(name.to_string()));
-
- self
}
/// Transfers the ownership of the guild to another user by Id.
///
/// **Note**: The current user must be the owner of the guild.
- pub fn owner<U: Into<UserId>>(mut self, user_id: U) -> Self {
+ pub fn owner<U: Into<UserId>>(&mut self, user_id: U) {
let id = Value::Number(Number::from(user_id.into().0));
self.0.insert("owner_id", id);
-
- self
}
/// Set the voice region of the server.
@@ -121,7 +115,11 @@ impl EditGuild {
///
/// // assuming a `guild` has already been bound
///
- /// guild.edit(|g| g.region(Region::UsWest))?;
+ /// guild.edit(|mut g| {
+ /// g.region(Region::UsWest);
+ ///
+ /// g
+ /// })?;
/// # Ok(())
/// # }
/// #
@@ -131,10 +129,8 @@ impl EditGuild {
/// ```
///
/// [`Region::UsWest`]: ../model/guild/enum.Region.html#variant.UsWest
- pub fn region(mut self, region: Region) -> Self {
+ pub fn region(&mut self, region: Region) {
self.0.insert("region", Value::String(region.name().to_string()));
-
- self
}
/// Set the splash image of the guild on the invitation page.
@@ -143,11 +139,9 @@ impl EditGuild {
/// You can check this through a guild's [`features`] list.
///
/// [`features`]: ../model/guild/struct.Guild.html#structfield.features
- pub fn splash(mut self, splash: Option<&str>) -> Self {
+ pub fn splash(&mut self, splash: Option<&str>) {
let splash = splash.map_or(Value::Null, |x| Value::String(x.to_string()));
self.0.insert("splash", splash);
-
- self
}
/// Set the verification level of the guild. This can restrict what a
@@ -166,26 +160,36 @@ impl EditGuild {
///
/// // assuming a `guild` has already been bound
///
- /// if let Err(why) = guild.edit(|g| g.verification_level(VerificationLevel::High)) {
+ /// let edit = guild.edit(|mut g| {
+ /// g.verification_level(VerificationLevel::High);
+ ///
+ /// g
+ /// });
+ ///
+ /// if let Err(why) = edit {
/// println!("Error setting verification level: {:?}", why);
/// }
///
/// // additionally, you may pass in just an integer of the verification
/// // level
///
- /// if let Err(why) = guild.edit(|g| g.verification_level(3)) {
+ /// let edit = guild.edit(|mut g| {
+ /// g.verification_level(3);
+ ///
+ /// g
+ /// });
+ ///
+ /// if let Err(why) = edit {
/// println!("Error setting verification level: {:?}", why);
/// }
/// ```
///
/// [`VerificationLevel`]: ../model/guild/enum.VerificationLevel.html
/// [`VerificationLevel::High`]: ../model/guild/enum.VerificationLevel.html#variant.High
- pub fn verification_level<V>(mut self, verification_level: V) -> Self
+ pub fn verification_level<V>(&mut self, verification_level: V)
where V: Into<VerificationLevel> {
let num = Value::Number(Number::from(verification_level.into().num()));
self.0.insert("verification_level", num);
-
- self
}
}
diff --git a/src/builder/edit_member.rs b/src/builder/edit_member.rs
index 19edb5e..8769c64 100644
--- a/src/builder/edit_member.rs
+++ b/src/builder/edit_member.rs
@@ -16,10 +16,8 @@ impl EditMember {
/// Requires the [Deafen Members] permission.
///
/// [Deafen Members]: ../model/permissions/constant.DEAFEN_MEMBERS.html
- pub fn deafen(mut self, deafen: bool) -> Self {
+ pub fn deafen(&mut self, deafen: bool) {
self.0.insert("deaf", Value::Bool(deafen));
-
- self
}
/// Whether to mute the member.
@@ -27,10 +25,8 @@ impl EditMember {
/// Requires the [Mute Members] permission.
///
/// [Mute Members]: ../model/permissions/constant.MUTE_MEMBERS.html
- pub fn mute(mut self, mute: bool) -> Self {
+ pub fn mute(&mut self, mute: bool) {
self.0.insert("mute", Value::Bool(mute));
-
- self
}
/// Changes the member's nickname. Pass an empty string to reset the
@@ -39,10 +35,8 @@ impl EditMember {
/// Requires the [Manage Nicknames] permission.
///
/// [Manage Nicknames]: ../model/permissions/constant.MANAGE_NICKNAMES.html
- pub fn nickname(mut self, nickname: &str) -> Self {
+ pub fn nickname(&mut self, nickname: &str) {
self.0.insert("nick", Value::String(nickname.to_string()));
-
- self
}
/// Set the list of roles that the member should have.
@@ -50,15 +44,13 @@ impl EditMember {
/// Requires the [Manage Roles] permission to modify.
///
/// [Manage Roles]: ../model/permissions/constant.MANAGE_ROLES.html
- pub fn roles<T: AsRef<RoleId>, It: IntoIterator<Item=T>>(mut self, roles: It) -> Self {
+ pub fn roles<T: AsRef<RoleId>, It: IntoIterator<Item=T>>(&mut self, roles: It) {
let role_ids = roles
.into_iter()
.map(|x| Value::Number(Number::from(x.as_ref().0)))
.collect();
self.0.insert("roles", Value::Array(role_ids));
-
- self
}
/// The Id of the voice channel to move the member to.
@@ -66,10 +58,9 @@ impl EditMember {
/// Requires the [Move Members] permission.
///
/// [Move Members]: ../model/permissions/constant.MOVE_MEMBERS.html
- pub fn voice_channel<C: Into<ChannelId>>(mut self, channel_id: C) -> Self {
+ pub fn voice_channel<C: Into<ChannelId>>(&mut self, channel_id: C) {
let num = Value::Number(Number::from(channel_id.into().0));
- self.0.insert("channel_id", num);
- self
+ self.0.insert("channel_id", num);
}
}
diff --git a/src/builder/edit_message.rs b/src/builder/edit_message.rs
index 29da46a..7c15e2b 100644
--- a/src/builder/edit_message.rs
+++ b/src/builder/edit_message.rs
@@ -14,8 +14,11 @@ use utils::{self, VecMap};
/// #
/// # let mut message = ChannelId(7).message(MessageId(8)).unwrap();
/// #
+/// let _ = message.edit(|mut m| {
+/// m.content("hello");
///
-/// let _ = message.edit(|m| m.content("hello"));
+/// m
+/// });
/// ```
///
/// [`Message`]: ../model/channel/struct.Message.html
@@ -26,20 +29,15 @@ impl EditMessage {
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
- pub fn content<D: Display>(mut self, content: D) -> Self {
+ pub fn content<D: Display>(&mut self, content: D) {
self.0.insert("content", Value::String(content.to_string()));
-
- self
}
/// Set an embed for the message.
- pub fn embed<F>(mut self, f: F) -> Self
- where F: FnOnce(CreateEmbed) -> CreateEmbed {
+ pub fn embed<F: FnOnce(CreateEmbed) -> CreateEmbed>(&mut self, f: F) {
let map = utils::vecmap_to_json_map(f(CreateEmbed::default()).0);
let embed = Value::Object(map);
self.0.insert("embed", embed);
-
- self
}
}
diff --git a/src/builder/edit_profile.rs b/src/builder/edit_profile.rs
index 84c1902..e4f91b0 100644
--- a/src/builder/edit_profile.rs
+++ b/src/builder/edit_profile.rs
@@ -34,8 +34,10 @@ impl EditProfile {
/// let base64 = utils::read_image("./my_image.jpg")
/// .expect("Failed to read image");
///
- /// let _ = context.edit_profile(|profile| {
- /// profile.avatar(Some(&base64))
+ /// let _ = context.edit_profile(|mut profile| {
+ /// profile.avatar(Some(&base64));
+ ///
+ /// profile
/// });
/// # }
/// }
@@ -46,11 +48,10 @@ impl EditProfile {
/// ```
///
/// [`utils::read_image`]: ../fn.read_image.html
- pub fn avatar(mut self, avatar: Option<&str>) -> Self {
+ pub fn avatar(&mut self, avatar: Option<&str>) {
let avatar = avatar.map_or(Value::Null, |x| Value::String(x.to_string()));
- self.0.insert("avatar", avatar);
- self
+ self.0.insert("avatar", avatar);
}
/// Modifies the current user's password.
@@ -59,10 +60,8 @@ impl EditProfile {
/// [provided].
///
/// [provided]: #method.password
- pub fn new_password(mut self, new_password: &str) -> Self {
+ pub fn new_password(&mut self, new_password: &str) {
self.0.insert("new_password", Value::String(new_password.to_string()));
-
- self
}
/// Used for providing the current password as verification when
@@ -70,10 +69,8 @@ impl EditProfile {
///
/// [modifying the password]: #method.new_password
/// [modifying the associated email address]: #method.email
- pub fn password(mut self, password: &str) -> Self {
+ pub fn password(&mut self, password: &str) {
self.0.insert("password", Value::String(password.to_string()));
-
- self
}
/// Modifies the current user's username.
@@ -82,9 +79,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) -> Self {
+ pub fn username(&mut self, username: &str) {
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 1deb57d..f86a360 100644
--- a/src/builder/edit_role.rs
+++ b/src/builder/edit_role.rs
@@ -28,10 +28,13 @@ use utils::VecMap;
/// #
/// // assuming a `channel_id` and `guild_id` has been bound
///
-/// let role = guild_id.create_role(|r| r
-/// .hoist(true)
-/// .mentionable(true)
-/// .name("a test role"));
+/// let role = guild_id.create_role(|mut r| {
+/// r.hoist(true);
+/// r.mentionable(true);
+/// r.name("a test role");
+///
+/// r
+/// });
/// ```
///
/// [`PartialGuild::create_role`]: ../model/guild/struct.PartialGuild.html#method.create_role
@@ -72,47 +75,37 @@ impl EditRole {
}
/// Sets the colour of the role.
- pub fn colour(mut self, colour: u64) -> Self {
+ pub fn colour(&mut self, colour: u64) {
self.0.insert("color", Value::Number(Number::from(colour)));
-
- self
}
/// Whether or not to hoist the role above lower-positioned role in the user
/// list.
- pub fn hoist(mut self, hoist: bool) -> Self {
+ pub fn hoist(&mut self, hoist: bool) {
self.0.insert("hoist", Value::Bool(hoist));
-
- self
}
/// Whether or not to make the role mentionable, notifying its users.
- pub fn mentionable(mut self, mentionable: bool) -> Self {
+ pub fn mentionable(&mut self, mentionable: bool) {
self.0.insert("mentionable", Value::Bool(mentionable));
-
- self
}
/// The name of the role to set.
- pub fn name(mut self, name: &str) -> Self {
- self.0
- .insert("name", Value::String(name.to_string()));
-
- self
+ pub fn name(&mut self, name: &str) {
+ self.0.insert("name", Value::String(name.to_string()));
}
/// The set of permissions to assign the role.
- pub fn permissions(mut self, permissions: Permissions) -> Self {
- self.0.insert("permissions", Value::Number(Number::from(permissions.bits())));
-
- self
+ pub fn permissions(&mut self, permissions: Permissions) {
+ self.0.insert(
+ "permissions",
+ Value::Number(Number::from(permissions.bits())),
+ );
}
/// The position to assign the role in the role list. This correlates to the
/// role's position in the user list.
- pub fn position(mut self, position: u8) -> Self {
+ pub fn position(&mut self, position: u8) {
self.0.insert("position", Value::Number(Number::from(position)));
-
- self
}
}
diff --git a/src/builder/execute_webhook.rs b/src/builder/execute_webhook.rs
index 65823bb..7c32a28 100644
--- a/src/builder/execute_webhook.rs
+++ b/src/builder/execute_webhook.rs
@@ -26,21 +26,30 @@ use utils::VecMap;
/// let webhook = http::get_webhook_with_token(id, token)
/// .expect("valid webhook");
///
-/// let website = Embed::fake(|e| e
-/// .title("The Rust Language Website")
-/// .description("Rust is a systems programming language.")
-/// .colour(Colour::from_rgb(222, 165, 132)));
+/// let website = Embed::fake(|mut e| {
+/// e.title("The Rust Language Website");
+/// e.description("Rust is a systems programming language.");
+/// e.colour(Colour::from_rgb(222, 165, 132));
///
-/// let resources = Embed::fake(|e| e
-/// .title("Rust Resources")
-/// .description("A few resources to help with learning Rust")
-/// .colour(0xDEA584)
-/// .field("The Rust Book", "A comprehensive resource for Rust.", false)
-/// .field("Rust by Example", "A collection of Rust examples", false));
+/// e
+/// });
///
-/// let _ = webhook.execute(false, |w| w
-/// .content("Here's some information on Rust:")
-/// .embeds(vec![website, resources]));
+/// let resources = Embed::fake(|mut e| {
+/// e.title("Rust Resources");
+/// e.description("A few resources to help with learning Rust");
+/// e.colour(0xDEA584);
+/// e.field("The Rust Book", "A comprehensive resource for Rust.", false);
+/// e.field("Rust by Example", "A collection of Rust examples", false);
+///
+/// e
+/// });
+///
+/// let _ = webhook.execute(false, |mut w| {
+/// w.content("Here's some information on Rust:");
+/// w.embeds(vec![website, resources]);
+///
+/// w
+/// });
/// ```
///
/// [`Webhook`]: ../model/webhook/struct.Webhook.html
@@ -63,14 +72,15 @@ impl ExecuteWebhook {
/// #
/// let avatar_url = "https://i.imgur.com/KTs6whd.jpg";
///
- /// let _ = webhook.execute(false, |w| w
- /// .avatar_url(avatar_url)
- /// .content("Here's a webhook"));
+ /// let _ = webhook.execute(false, |mut w| {
+ /// w.avatar_url(avatar_url);
+ /// w.content("Here's a webhook");
+ ///
+ /// w
+ /// });
/// ```
- pub fn avatar_url(mut self, avatar_url: &str) -> Self {
+ pub fn avatar_url(&mut self, avatar_url: &str) {
self.0.insert("avatar_url", Value::String(avatar_url.to_string()));
-
- self
}
/// Set the content of the message.
@@ -87,16 +97,20 @@ impl ExecuteWebhook {
/// #
/// # let webhook = rest::get_webhook_with_token(0, "").unwrap();
/// #
- /// if let Err(why) = webhook.execute(false, |w| w.content("foo")) {
+ /// let execution = webhook.execute(false, |mut w| {
+ /// w.content("foo");
+ ///
+ /// w
+ /// });
+ ///
+ /// if let Err(why) = execution {
/// println!("Err sending webhook: {:?}", why);
/// }
/// ```
///
/// [`embeds`]: #method.embeds
- pub fn content(mut self, content: &str) -> Self {
+ pub fn content(&mut self, content: &str) {
self.0.insert("content", Value::String(content.to_string()));
-
- self
}
/// Set the embeds associated with the message.
@@ -112,10 +126,8 @@ impl ExecuteWebhook {
/// [`Embed::fake`]: ../model/channel/struct.Embed.html#method.fake
/// [`Webhook::execute`]: ../model/webhook/struct.Webhook.html#method.execute
/// [struct-level documentation]: #examples
- pub fn embeds(mut self, embeds: Vec<Value>) -> Self {
+ pub fn embeds(&mut self, embeds: Vec<Value>) {
self.0.insert("embeds", Value::Array(embeds));
-
- self
}
/// Whether the message is a text-to-speech message.
@@ -129,14 +141,19 @@ impl ExecuteWebhook {
/// #
/// # let webhook = rest::get_webhook_with_token(0, "").unwrap();
/// #
- /// if let Err(why) = webhook.execute(false, |w| w.content("hello").tts(true)) {
+ /// let execution = webhook.execute(false, |mut w| {
+ /// w.content("hello");
+ /// w.tts(true);
+ ///
+ /// w
+ /// });
+ ///
+ /// if let Err(why) = execution {
/// println!("Err sending webhook: {:?}", why);
/// }
/// ```
- pub fn tts(mut self, tts: bool) -> Self {
+ pub fn tts(&mut self, tts: bool) {
self.0.insert("tts", Value::Bool(tts));
-
- self
}
/// Override the default username of the webhook.
@@ -150,14 +167,19 @@ impl ExecuteWebhook {
/// #
/// # let webhook = rest::get_webhook_with_token(0, "").unwrap();
/// #
- /// if let Err(why) = webhook.execute(false, |w| w.content("hello").username("hakase")) {
+ /// let execution = webhook.execute(false, |mut w| {
+ /// w.content("hello");
+ /// w.username("hakase");
+ ///
+ /// w
+ /// });
+ ///
+ /// if let Err(why) = execution {
/// println!("Err sending webhook: {:?}", why);
/// }
/// ```
- pub fn username(mut self, username: &str) -> Self {
+ pub fn username(&mut self, username: &str) {
self.0.insert("username", Value::String(username.to_string()));
-
- self
}
}
diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs
index f302ff0..548fc94 100644
--- a/src/builder/get_messages.rs
+++ b/src/builder/get_messages.rs
@@ -29,17 +29,17 @@ use utils::VecMap;
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
-/// use serenity::builder::GetMessages;
/// use serenity::model::id::{ChannelId, MessageId};
///
-/// let retriever = GetMessages::default()
-/// .after(MessageId(158339864557912064))
-/// .limit(25);
-///
/// // you can then pass it into a function which retrieves messages:
/// let channel_id = ChannelId(81384788765712384);
///
-/// let _messages = channel_id.messages(|_| retriever)?;
+/// let _messages = channel_id.messages(|mut retriever| {
+/// retriever.after(MessageId(158339864557912064));
+/// retriever.limit(25);
+///
+/// retriever
+/// })?;
/// # Ok(())
/// # }
/// #
@@ -55,26 +55,20 @@ pub struct GetMessages(pub VecMap<&'static str, u64>);
impl GetMessages {
/// Indicates to retrieve the messages after a specific message, given by
/// its Id.
- pub fn after<M: Into<MessageId>>(mut self, message_id: M) -> Self {
+ pub fn after<M: Into<MessageId>>(&mut self, message_id: M) {
self.0.insert("after", message_id.into().0);
-
- self
}
/// Indicates to retrieve the messages _around_ a specific message in either
/// direction (before+after) the given message.
- pub fn around<M: Into<MessageId>>(mut self, message_id: M) -> Self {
+ pub fn around<M: Into<MessageId>>(&mut self, message_id: M) {
self.0.insert("around", message_id.into().0);
-
- self
}
/// Indicates to retrieve the messages before a specific message, given by
/// its Id.
- pub fn before<M: Into<MessageId>>(mut self, message_id: M) -> Self {
+ pub fn before<M: Into<MessageId>>(&mut self, message_id: M) {
self.0.insert("before", message_id.into().0);
-
- self
}
/// The maximum number of messages to retrieve for the query.
@@ -84,15 +78,12 @@ impl GetMessages {
/// **Note**: This field is capped to 100 messages due to a Discord
/// limitation. If an amount larger than 100 is supplied, it will be
/// reduced.
- pub fn limit(mut self, limit: u64) -> Self {
- self.0
- .insert("limit", if limit > 100 { 100 } else { limit });
-
- self
+ pub fn limit(&mut self, limit: u64) {
+ self.0.insert("limit", if limit > 100 { 100 } else { limit });
}
/// This is a function that is here for completeness. You do not need to
/// call this - except to clear previous calls to `after`, `around`, and
/// `before` - as it is the default value.
- pub fn most_recent(self) -> Self { self }
+ pub fn most_recent(&self) { }
}
diff --git a/src/client/context.rs b/src/client/context.rs
index d581ffb..9bb6f68 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -78,7 +78,11 @@ impl Context {
/// impl EventHandler for Handler {
/// fn message(&self, ctx: Context, msg: Message) {
/// if msg.content == "!changename" {
- /// ctx.edit_profile(|e| e.username("Edward Elric"));
+ /// ctx.edit_profile(|mut e| {
+ /// e.username("Edward Elric");
+ ///
+ /// e
+ /// });
/// }
/// }
/// }
diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs
index 8c0e1b4..7f6ca72 100644
--- a/src/framework/standard/help_commands.rs
+++ b/src/framework/standard/help_commands.rs
@@ -49,8 +49,15 @@ use super::{
use utils::Colour;
fn error_embed(channel_id: &ChannelId, input: &str, colour: Colour) {
- let _ = channel_id.send_message(|m| {
- m.embed(|e| e.colour(colour).description(input))
+ let _ = channel_id.send_message(|mut m| {
+ m.embed(|mut e| {
+ e.colour(colour);
+ e.description(input);
+
+ e
+ });
+
+ m
});
}
@@ -167,34 +174,36 @@ pub fn with_embeds<H: BuildHasher>(
return Ok(());
}
- let _ = msg.channel_id.send_message(|m| {
- m.embed(|e| {
- let mut embed = e.colour(help_options.embed_success_colour).title(command_name);
+ let _ = msg.channel_id.send_message(|mut m| {
+ m.embed(|mut embed| {
+ embed.colour(help_options.embed_success_colour);
+
+ embed.title(command_name.clone());
if let Some(ref desc) = command.desc {
- embed = embed.description(desc);
+ embed.description(desc);
}
if let Some(ref usage) = command.usage {
let value = format!("`{} {}`", command_name, usage);
- embed = embed.field(&help_options.usage_label, value, true);
+ embed.field(&help_options.usage_label, value, true);
}
if let Some(ref example) = command.example {
let value = format!("`{} {}`", command_name, example);
- embed = embed.field(&help_options.usage_sample_label, value, true);
+ embed.field(&help_options.usage_sample_label, value, true);
}
if group_name != "Ungrouped" {
- embed = embed.field(&help_options.grouped_label, group_name, true);
+ embed.field(&help_options.grouped_label, group_name, true);
}
if !command.aliases.is_empty() {
let aliases = command.aliases.join(", ");
- embed = embed.field(&help_options.aliases_label, aliases, true);
+ embed.field(&help_options.aliases_label, aliases, true);
}
let available = if command.dm_only {
@@ -205,10 +214,12 @@ pub fn with_embeds<H: BuildHasher>(
&help_options.dm_and_guild_text
};
- embed = embed.field(&help_options.available_text, available, true);
+ embed.field(&help_options.available_text, available, true);
embed
- })
+ });
+
+ m
});
return Ok(());
@@ -221,22 +232,24 @@ pub fn with_embeds<H: BuildHasher>(
return Ok(());
}
- let _ = msg.channel_id.send_message(|m| {
- m.embed(|mut e| {
+ let _ = msg.channel_id.send_message(|mut m| {
+ m.embed(|mut embed| {
let striked_command_tip = if msg.is_private() {
- &help_options.striked_commands_tip_in_guild
- } else {
- &help_options.striked_commands_tip_in_dm
- };
-
- if let Some(ref striked_command_text) = striked_command_tip {
- e = e.colour(help_options.embed_success_colour).description(
- format!("{}\n{}", &help_options.individual_command_tip, striked_command_text),
- );
+ &help_options.striked_commands_tip_in_guild
} else {
- e = e.colour(help_options.embed_success_colour).description(
+ &help_options.striked_commands_tip_in_dm
+ };
+
+ if let Some(ref striked_command_text) = striked_command_tip{
+ embed.colour(help_options.embed_success_colour);
+ embed.description(format!(
+ "{}\n{}",
&help_options.individual_command_tip,
- );
+ &striked_command_text,
+ ));
+ } else {
+ embed.colour(help_options.embed_success_colour);
+ embed.description(&help_options.individual_command_tip);
}
let mut group_names = groups.keys().collect::<Vec<_>>();
@@ -302,11 +315,14 @@ pub fn with_embeds<H: BuildHasher>(
}
if has_commands {
- e = e.field(&group_name[..], &desc[..], true);
+ embed.field(&group_name[..], &desc[..], true);
}
}
- e
- })
+
+ embed
+ });
+
+ m
});
Ok(())
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index f6d9963..f4336fc 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -402,7 +402,11 @@ impl ChannelId {
/// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
pub fn say<D: ::std::fmt::Display>(&self, content: D) -> Result<Message> {
- self.send_message(|m| m.content(content))
+ self.send_message(|mut m| {
+ m.content(content);
+
+ m
+ })
}
/// Sends a file along with optional message contents. The filename _must_
@@ -426,7 +430,11 @@ impl ChannelId {
///
/// let paths = vec!["/path/to/file.jpg", "path/to/file2.jpg"];
///
- /// let _ = channel_id.send_files(paths, |m| m.content("a file"));
+ /// let _ = channel_id.send_files(paths, |mut m| {
+ /// m.content("a file");
+ ///
+ /// m
+ /// });
/// ```
///
/// Send files using `File`:
@@ -442,7 +450,11 @@ impl ChannelId {
///
/// let files = vec![(&f1, "my_file.jpg"), (&f2, "my_file2.jpg")];
///
- /// let _ = channel_id.send_files(files, |m| m.content("a file"));
+ /// let _ = channel_id.send_files(files, |mut m| {
+ /// m.content("a file");
+ ///
+ /// m
+ /// });
/// ```
///
/// # Errors
diff --git a/src/model/channel/embed.rs b/src/model/channel/embed.rs
index 8837a8d..8792d18 100644
--- a/src/model/channel/embed.rs
+++ b/src/model/channel/embed.rs
@@ -80,10 +80,13 @@ impl Embed {
/// ```rust,no_run
/// use serenity::model::channel::Embed;
///
- /// let embed = Embed::fake(|e| e
- /// .title("Embed title")
- /// .description("Making a basic embed")
- /// .field("A field", "Has some content.", false));
+ /// let embed = Embed::fake(|mut e| {
+ /// e.title("Embed title");
+ /// e.description("Making a basic embed");
+ /// e.field("A field", "Has some content.", false);
+ ///
+ /// e
+ /// });
/// ```
#[inline]
pub fn fake<F>(f: F) -> Value
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs
index 533aaf2..c6d9031 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -496,8 +496,11 @@ impl GuildChannel {
/// },
/// };
///
- /// let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |m|
- /// m.content("here's a cat"));
+ /// let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |mut m| {
+ /// m.content("here's a cat");
+ ///
+ /// m
+ /// });
/// }
/// }
///
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index 978e181..fdc7787 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -221,11 +221,11 @@ impl Message {
let mut builder = EditMessage::default();
if !self.content.is_empty() {
- builder = builder.content(&self.content);
+ builder.content(&self.content);
}
if let Some(embed) = self.embeds.get(0) {
- builder = builder.embed(|_| CreateEmbed::from(embed.clone()));
+ builder.embed(|_| CreateEmbed::from(embed.clone()));
}
let map = serenity_utils::vecmap_to_json_map(f(builder).0);
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index c95c07f..ce3dd01 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -113,7 +113,8 @@ impl Member {
pub fn add_roles(&mut self, role_ids: &[RoleId]) -> Result<()> {
self.roles.extend_from_slice(role_ids);
- let builder = EditMember::default().roles(&self.roles);
+ let mut builder = EditMember::default();
+ builder.roles(&self.roles);
let map = utils::vecmap_to_json_map(builder.0);
match http::edit_member(self.guild_id.0, self.user.read().id.0, &map) {
@@ -395,7 +396,8 @@ impl Member {
pub fn remove_roles(&mut self, role_ids: &[RoleId]) -> Result<()> {
self.roles.retain(|r| !role_ids.contains(r));
- let builder = EditMember::default().roles(&self.roles);
+ let mut builder = EditMember::default();
+ builder.roles(&self.roles);
let map = utils::vecmap_to_json_map(builder.0);
match http::edit_member(self.guild_id.0, self.user.read().id.0, &map) {
diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs
index 53ec478..800d178 100644
--- a/src/model/guild/role.rs
+++ b/src/model/guild/role.rs
@@ -83,7 +83,11 @@ impl Role {
/// # let role = RoleId(7).find().unwrap();
/// // assuming a `role` has already been bound
//
- /// role.edit(|r| r.hoist(true));
+ /// role.edit(|mut r| {
+ /// r.hoist(true);
+ ///
+ /// r
+ /// });
/// ```
///
/// [`Role`]: struct.Role.html
diff --git a/src/model/user.rs b/src/model/user.rs
index 330f319..131e891 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -436,7 +436,13 @@ impl User {
/// url,
/// );
///
- /// match msg.author.direct_message(|m| m.content(&help)) {
+ /// let dm = msg.author.direct_message(|mut m| {
+ /// m.content(&help);
+ ///
+ /// m
+ /// });
+ ///
+ /// match dm {
/// Ok(_) => {
/// let _ = msg.react('👌');
/// },
diff --git a/src/model/webhook.rs b/src/model/webhook.rs
index ab07b43..8f2c6b2 100644
--- a/src/model/webhook.rs
+++ b/src/model/webhook.rs
@@ -160,7 +160,11 @@ impl Webhook {
/// let mut webhook = http::get_webhook_with_token(id, token)
/// .expect("valid webhook");
///
- /// let _ = webhook.execute(false, |w| w.content("test")).expect("Error executing");
+ /// let _ = webhook.execute(false, |mut w| {
+ /// w.content("test");
+ ///
+ /// w
+ /// });
/// ```
///
/// Execute a webhook with message content of `test`, overriding the
@@ -176,18 +180,23 @@ impl Webhook {
/// let mut webhook = http::get_webhook_with_token(id, token)
/// .expect("valid webhook");
///
- /// let embed = Embed::fake(|e| e
- /// .title("Rust's website")
- /// .description("Rust is a systems programming language that runs
- /// blazingly fast, prevents segfaults, and guarantees
- /// thread safety.")
- /// .url("https://rust-lang.org"));
- ///
- /// let _ = webhook.execute(false, |w| w
- /// .content("test")
- /// .username("serenity")
- /// .embeds(vec![embed]))
- /// .expect("Error executing");
+ /// let embed = Embed::fake(|mut e| {
+ /// e.title("Rust's website");
+ /// e.description("Rust is a systems programming language that runs
+ /// blazingly fast, prevents segfaults, and guarantees
+ /// thread safety.");
+ /// e.url("https://rust-lang.org");
+ ///
+ /// e
+ /// });
+ ///
+ /// let _ = webhook.execute(false, |mut w| {
+ /// w.content("test");
+ /// w.username("serenity");
+ /// w.embeds(vec![embed]);
+ ///
+ /// w
+ /// });
/// ```
#[inline]
pub fn execute<F: FnOnce(ExecuteWebhook) -> ExecuteWebhook>(&self,