diff options
| author | Zeyla Hellyer <[email protected]> | 2018-04-26 21:02:02 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-05-27 19:21:18 -0700 |
| commit | 309eee7ba66de7870011825a9130828e9b49e83c (patch) | |
| tree | 202559d698f927b0f8840804b7b5ccc83cb325f0 /src/builder/edit_guild.rs | |
| parent | Remove user account relation docs/functions (diff) | |
| download | serenity-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/builder/edit_guild.rs')
| -rw-r--r-- | src/builder/edit_guild.rs | 60 |
1 files changed, 32 insertions, 28 deletions
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 } } |