diff options
| author | Zeyla Hellyer <[email protected]> | 2017-02-28 11:43:53 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-02-28 11:43:53 -0800 |
| commit | 28743c8632458b79b472e3719d4754b57e116ad0 (patch) | |
| tree | 2c892dfbc7651577d4c576ad9d6c395e0523c61b /src/model | |
| parent | Standardize message editing methods (diff) | |
| download | serenity-28743c8632458b79b472e3719d4754b57e116ad0.tar.xz serenity-28743c8632458b79b472e3719d4754b57e116ad0.zip | |
Pass by reference where possible
A lot of the `rest` methods took - for example a Map - by value, where
they could instead take a reference. While this only prevents one clone
in the library, user-land code should no longer need to clone maps when
using the `rest` module.
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/channel.rs | 30 | ||||
| -rw-r--r-- | src/model/guild.rs | 32 | ||||
| -rw-r--r-- | src/model/invite.rs | 2 | ||||
| -rw-r--r-- | src/model/user.rs | 14 | ||||
| -rw-r--r-- | src/model/webhook.rs | 4 |
5 files changed, 41 insertions, 41 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs index 72142f1..60e608d 100644 --- a/src/model/channel.rs +++ b/src/model/channel.rs @@ -557,7 +557,7 @@ impl ChannelId { .insert("type", kind) .build(); - rest::create_permission(self.0, id, map) + rest::create_permission(self.0, id, &map) } /// React to a [`Message`] with a custom [`Emoji`] or unicode character. @@ -575,7 +575,7 @@ impl ChannelId { #[inline] pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R) -> Result<()> where M: Into<MessageId>, R: Into<ReactionType> { - rest::create_reaction(self.0, message_id.into().0, reaction_type.into()) + rest::create_reaction(self.0, message_id.into().0, &reaction_type.into()) } /// Deletes this channel, returning the channel on a successful deletion. @@ -620,7 +620,7 @@ impl ChannelId { let map = ObjectBuilder::new().insert("messages", ids).build(); - rest::delete_messages(self.0, map) + rest::delete_messages(self.0, &map) } /// Deletes all permission overrides in the channel from a member or role. @@ -647,7 +647,7 @@ impl ChannelId { rest::delete_reaction(self.0, message_id.into().0, user_id.map(|uid| uid.0), - reaction_type.into()) + &reaction_type.into()) } @@ -677,7 +677,7 @@ impl ChannelId { /// [Manage Channel]: permissions/constant.MANAGE_CHANNELS.html #[inline] pub fn edit<F: FnOnce(EditChannel) -> EditChannel>(&self, f: F) -> Result<GuildChannel> { - rest::edit_channel(self.0, f(EditChannel::default()).0.build()) + rest::edit_channel(self.0, &f(EditChannel::default()).0.build()) } /// Edits a [`Message`] in the channel given its Id. @@ -711,7 +711,7 @@ impl ChannelId { } } - rest::edit_message(self.0, message_id.into().0, Value::Object(map)) + rest::edit_message(self.0, message_id.into().0, &Value::Object(map)) } /// Search the cache for the channel with the Id. @@ -798,7 +798,7 @@ impl ChannelId { rest::get_reaction_users(self.0, message_id.into().0, - reaction_type.into(), + &reaction_type.into(), limit, after.map(|u| u.into().0)) } @@ -950,7 +950,7 @@ impl ChannelId { } } - rest::send_message(self.0, Value::Object(map)) + rest::send_message(self.0, &Value::Object(map)) } /// Unpins a [`Message`] in the channel given by its Id. @@ -1470,7 +1470,7 @@ impl Message { let map = f(builder).0; - match rest::edit_message(self.channel_id.0, self.id.0, Value::Object(map)) { + match rest::edit_message(self.channel_id.0, self.id.0, &Value::Object(map)) { Ok(edited) => { mem::replace(self, edited); @@ -1621,7 +1621,7 @@ impl Message { rest::create_reaction(self.channel_id.0, self.id.0, - reaction_type.into()) + &reaction_type.into()) } /// Replies to the user, mentioning them prior to the content in the form @@ -1669,7 +1669,7 @@ impl Message { .insert("tts", false) .build(); - rest::send_message(self.channel_id.0, map) + rest::send_message(self.channel_id.0, &map) } /// Unpins the message from its channel. @@ -2094,7 +2094,7 @@ impl GuildChannel { let map = f(CreateInvite::default()).0.build(); - rest::create_invite(self.id.0, map) + rest::create_invite(self.id.0, &map) } /// Creates a [permission overwrite][`PermissionOverwrite`] for either a @@ -2289,7 +2289,7 @@ impl GuildChannel { let edited = f(EditChannel(map)).0.build(); - match rest::edit_channel(self.id.0, edited) { + match rest::edit_channel(self.id.0, &edited) { Ok(channel) => { mem::replace(self, channel); @@ -2571,7 +2571,7 @@ impl Reaction { rest::delete_reaction(self.channel_id.0, self.message_id.0, user_id, - self.emoji.clone()) + &self.emoji) } /// Retrieves the list of [`User`]s who have reacted to a [`Message`] with a @@ -2606,7 +2606,7 @@ impl Reaction { U: Into<UserId> { rest::get_reaction_users(self.channel_id.0, self.message_id.0, - reaction_type.into(), + &reaction_type.into(), limit.unwrap_or(50), after.map(|u| u.into().0)) } diff --git a/src/model/guild.rs b/src/model/guild.rs index 03c5cfc..8fa6d0e 100644 --- a/src/model/guild.rs +++ b/src/model/guild.rs @@ -79,7 +79,7 @@ impl Emoji { .insert("name", name) .build(); - match rest::edit_emoji(guild_id.0, self.id.0, map) { + match rest::edit_emoji(guild_id.0, self.id.0, &map) { Ok(emoji) => { mem::replace(self, emoji); @@ -276,7 +276,7 @@ impl Guild { .insert("region", region.name()) .build(); - rest::create_guild(map) + rest::create_guild(&map) } /// Creates a new [`Channel`] in the guild. @@ -1181,7 +1181,7 @@ impl GuildId { .insert("type", kind.name()) .build(); - rest::create_channel(self.0, map) + rest::create_channel(self.0, &map) } /// Creates an emoji in the guild with a name and base64-encoded image. @@ -1207,7 +1207,7 @@ impl GuildId { .insert("image", image) .build(); - rest::create_emoji(self.0, map) + rest::create_emoji(self.0, &map) } /// Creates an integration for the guild. @@ -1223,7 +1223,7 @@ impl GuildId { .insert("type", kind) .build(); - rest::create_guild_integration(self.0, integration_id.0, map) + rest::create_guild_integration(self.0, integration_id.0, &map) } /// Creates a new role in the guild with the data set, if any. @@ -1236,7 +1236,7 @@ impl GuildId { /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html #[inline] pub fn create_role<F: FnOnce(EditRole) -> EditRole>(&self, f: F) -> Result<Role> { - rest::create_role(self.0, f(EditRole::default()).0.build()) + rest::create_role(self.0, &f(EditRole::default()).0.build()) } /// Deletes the current guild if the current account is the owner of the @@ -1299,7 +1299,7 @@ impl GuildId { /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html #[inline] pub fn edit<F: FnOnce(EditGuild) -> EditGuild>(&mut self, f: F) -> Result<PartialGuild> { - rest::edit_guild(self.0, f(EditGuild::default()).0.build()) + rest::edit_guild(self.0, &f(EditGuild::default()).0.build()) } /// Edits an [`Emoji`]'s name in the guild. @@ -1315,7 +1315,7 @@ impl GuildId { pub fn edit_emoji<E: Into<EmojiId>>(&self, emoji_id: E, name: &str) -> Result<Emoji> { let map = ObjectBuilder::new().insert("name", name).build(); - rest::edit_emoji(self.0, emoji_id.into().0, map) + rest::edit_emoji(self.0, emoji_id.into().0, &map) } /// Edits the properties of member of the guild, such as muting or @@ -1334,7 +1334,7 @@ impl GuildId { #[inline] pub fn edit_member<F, U>(&self, user_id: U, f: F) -> Result<()> where F: FnOnce(EditMember) -> EditMember, U: Into<UserId> { - rest::edit_member(self.0, user_id.into().0, f(EditMember::default()).0.build()) + rest::edit_member(self.0, user_id.into().0, &f(EditMember::default()).0.build()) } /// Edits the current user's nickname for the guild. @@ -1368,7 +1368,7 @@ impl GuildId { #[inline] pub fn edit_role<F, R>(&self, role_id: R, f: F) -> Result<Role> where F: FnOnce(EditRole) -> EditRole, R: Into<RoleId> { - rest::edit_role(self.0, role_id.into().0, f(EditRole::default()).0.build()) + rest::edit_role(self.0, role_id.into().0, &f(EditRole::default()).0.build()) } /// Search the cache for the guild. @@ -1479,7 +1479,7 @@ impl GuildId { pub fn get_prune_count(&self, days: u16) -> Result<GuildPrune> { let map = ObjectBuilder::new().insert("days", days).build(); - rest::get_guild_prune_count(self.0, map) + rest::get_guild_prune_count(self.0, &map) } /// Retrieves the guild's webhooks. @@ -1518,7 +1518,7 @@ impl GuildId { -> Result<()> where C: Into<ChannelId>, U: Into<UserId> { let map = ObjectBuilder::new().insert("channel_id", channel_id.into().0).build(); - rest::edit_member(self.0, user_id.into().0, map) + rest::edit_member(self.0, user_id.into().0, &map) } /// Performs a search request to the API for the guild's [`Message`]s. @@ -1583,7 +1583,7 @@ impl GuildId { /// [Kick Members]: permissions/constant.KICK_MEMBERS.html #[inline] pub fn start_prune(&self, days: u16) -> Result<GuildPrune> { - rest::start_guild_prune(self.0, ObjectBuilder::new().insert("days", days).build()) + rest::start_guild_prune(self.0, &ObjectBuilder::new().insert("days", days).build()) } /// Unbans a [`User`] from the guild. @@ -1681,7 +1681,7 @@ impl Member { let map = EditMember::default().roles(&self.roles).0.build(); - match rest::edit_member(guild_id.0, self.user.read().unwrap().id.0, map) { + match rest::edit_member(guild_id.0, self.user.read().unwrap().id.0, &map) { Ok(()) => Ok(()), Err(why) => { self.roles.retain(|r| !role_ids.contains(r)); @@ -1763,7 +1763,7 @@ impl Member { let guild_id = self.find_guild()?; let map = f(EditMember::default()).0.build(); - rest::edit_member(guild_id.0, self.user.read().unwrap().id.0, map) + rest::edit_member(guild_id.0, self.user.read().unwrap().id.0, &map) } /// Finds the Id of the [`Guild`] that the member is in. @@ -1832,7 +1832,7 @@ impl Member { let map = EditMember::default().roles(&self.roles).0.build(); - match rest::edit_member(guild_id.0, self.user.read().unwrap().id.0, map) { + match rest::edit_member(guild_id.0, self.user.read().unwrap().id.0, &map) { Ok(()) => Ok(()), Err(why) => { self.roles.extend_from_slice(role_ids); diff --git a/src/model/invite.rs b/src/model/invite.rs index 10227bc..7d7378e 100644 --- a/src/model/invite.rs +++ b/src/model/invite.rs @@ -75,7 +75,7 @@ impl Invite { } } - rest::create_invite(channel_id.0, f(CreateInvite::default()).0.build()) + rest::create_invite(channel_id.0, &f(CreateInvite::default()).0.build()) } /// Deletes the invite. diff --git a/src/model/user.rs b/src/model/user.rs index be8f348..5b22e10 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -78,7 +78,7 @@ impl CurrentUser { map = map.insert("email", email) } - match rest::edit_profile(f(EditProfile(map)).0.build()) { + match rest::edit_profile(&f(EditProfile(map)).0.build()) { Ok(new) => { let _ = mem::replace(self, new); @@ -90,7 +90,7 @@ impl CurrentUser { /// Gets a list of guilds that the current user is in. pub fn guilds(&self) -> Result<Vec<GuildInfo>> { - rest::get_guilds(GuildPagination::After(GuildId(1)), 100) + rest::get_guilds(&GuildPagination::After(GuildId(1)), 100) } /// Returns a static formatted URL of the user's icon, if one exists. @@ -230,7 +230,7 @@ impl User { .insert("recipient_id", self.id.0) .build(); - rest::create_private_channel(map)?.id + rest::create_private_channel(&map)?.id } } else { let map = ObjectBuilder::new() @@ -245,7 +245,7 @@ impl User { .insert("tts", false) .build(); - rest::send_message(private_channel_id.0, map) + rest::send_message(private_channel_id.0, &map) } /// This is an alias of [direct_message]. @@ -386,14 +386,14 @@ impl UserId { pub fn create_dm_channel(&self) -> Result<PrivateChannel> { let map = ObjectBuilder::new().insert("recipient_id", self.0).build(); - rest::create_private_channel(map) + rest::create_private_channel(&map) } /// Deletes a profile note from a user. pub fn delete_note(&self) -> Result<()> { let map = ObjectBuilder::new().insert("note", "").build(); - rest::edit_note(self.0, map) + rest::edit_note(self.0, &map) } /// Edits the note that the current user has set for another user. @@ -409,7 +409,7 @@ impl UserId { pub fn edit_note(&self, note: &str) -> Result<()> { let map = ObjectBuilder::new().insert("note", note).build(); - rest::edit_note(self.0, map) + rest::edit_note(self.0, &map) } /// Search the cache for the user with the Id. diff --git a/src/model/webhook.rs b/src/model/webhook.rs index 7448fcf..4f831d9 100644 --- a/src/model/webhook.rs +++ b/src/model/webhook.rs @@ -83,7 +83,7 @@ impl Webhook { map = map.insert("name", name); } - match rest::edit_webhook_with_token(self.id.0, &self.token, map.build()) { + match rest::edit_webhook_with_token(self.id.0, &self.token, &map.build()) { Ok(replacement) => { mem::replace(self, replacement); @@ -142,7 +142,7 @@ impl Webhook { /// ``` #[inline] pub fn execute<F: FnOnce(ExecuteWebhook) -> ExecuteWebhook>(&self, f: F) -> Result<Message> { - rest::execute_webhook(self.id.0, &self.token, f(ExecuteWebhook::default()).0.build()) + rest::execute_webhook(self.id.0, &self.token, &f(ExecuteWebhook::default()).0.build()) } /// Retrieves the latest information about the webhook, editing the |