aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-02-28 11:43:53 -0800
committerZeyla Hellyer <[email protected]>2017-02-28 11:43:53 -0800
commit28743c8632458b79b472e3719d4754b57e116ad0 (patch)
tree2c892dfbc7651577d4c576ad9d6c395e0523c61b /src
parentStandardize message editing methods (diff)
downloadserenity-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')
-rw-r--r--src/client/context.rs2
-rw-r--r--src/client/gateway/prep.rs2
-rw-r--r--src/client/gateway/shard.rs2
-rw-r--r--src/client/mod.rs6
-rw-r--r--src/client/rest/mod.rs123
-rw-r--r--src/client/rest/ratelimiting.rs1
-rw-r--r--src/model/channel.rs30
-rw-r--r--src/model/guild.rs32
-rw-r--r--src/model/invite.rs2
-rw-r--r--src/model/user.rs14
-rw-r--r--src/model/webhook.rs4
11 files changed, 106 insertions, 112 deletions
diff --git a/src/client/context.rs b/src/client/context.rs
index 2954d2c..f46e351 100644
--- a/src/client/context.rs
+++ b/src/client/context.rs
@@ -106,7 +106,7 @@ impl Context {
let edited = f(EditProfile(map)).0.build();
- rest::edit_profile(edited)
+ rest::edit_profile(&edited)
}
/// Sets the current user as being [`Online`]. This maintains the current
diff --git a/src/client/gateway/prep.rs b/src/client/gateway/prep.rs
index 4fc98f3..97c7dee 100644
--- a/src/client/gateway/prep.rs
+++ b/src/client/gateway/prep.rs
@@ -91,7 +91,7 @@ pub fn build_gateway_url(base: &str) -> Result<RequestUrl> {
pub fn keepalive(interval: u64,
heartbeat_sent: Arc<Mutex<Instant>>,
mut sender: Sender<WebSocketStream>,
- channel: MpscReceiver<GatewayStatus>) {
+ channel: &MpscReceiver<GatewayStatus>) {
let mut base_interval = Duration::milliseconds(interval as i64);
let mut next_tick = time::get_time() + base_interval;
diff --git a/src/client/gateway/shard.rs b/src/client/gateway/shard.rs
index 8902b0b..a51c2dc 100644
--- a/src/client/gateway/shard.rs
+++ b/src/client/gateway/shard.rs
@@ -146,7 +146,7 @@ impl Shard {
ThreadBuilder::new()
.name(thread_name)
.spawn(move || {
- prep::keepalive(heartbeat_interval, heartbeat_clone, sender, rx)
+ prep::keepalive(heartbeat_interval, heartbeat_clone, sender, &rx)
})?;
// Parse READY
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 0da4b0e..0261833 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -782,7 +782,7 @@ impl Client {
for shard_number in shards_index..shards_total {
let shard_info = shard_data.map(|s| [shard_number, s[2]]);
- let boot = boot_shard(BootInfo {
+ let boot = boot_shard(&BootInfo {
gateway_url: gateway_url.clone(),
login_type: self.login_type,
shard_info: shard_info,
@@ -1195,7 +1195,7 @@ struct MonitorInfo {
token: String,
}
-fn boot_shard(info: BootInfo) -> Result<(Shard, ReadyEvent, Receiver<WebSocketStream>)> {
+fn boot_shard(info: &BootInfo) -> Result<(Shard, ReadyEvent, Receiver<WebSocketStream>)> {
// Make ten attempts to boot the shard, exponentially backing off; if it
// still doesn't boot after that, accept it as a failure.
//
@@ -1250,7 +1250,7 @@ fn monitor_shard(mut info: MonitorInfo) {
let mut boot_successful = false;
for _ in 0..3 {
- let boot = boot_shard(BootInfo {
+ let boot = boot_shard(&BootInfo {
gateway_url: info.gateway_url.clone(),
login_type: info.login_type,
shard_info: info.shard_info,
diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs
index 9c429c6..96cff30 100644
--- a/src/client/rest/mod.rs
+++ b/src/client/rest/mod.rs
@@ -224,8 +224,8 @@ pub fn broadcast_typing(channel_id: u64) -> Result<()> {
/// [`GuildChannel`]: ../../model/struct.GuildChannel.html
/// [docs]: https://discordapp.com/developers/docs/resources/guild#create-guild-channel
/// [Manage Channels]: ../../model/permissions/constant.MANAGE_CHANNELS.html
-pub fn create_channel(guild_id: u64, map: Value) -> Result<GuildChannel> {
- let body = serde_json::to_string(&map)?;
+pub fn create_channel(guild_id: u64, map: &Value) -> Result<GuildChannel> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdChannels(guild_id),
post(body),
"/guilds/{}/channels",
@@ -244,8 +244,8 @@ pub fn create_channel(guild_id: u64, map: Value) -> Result<GuildChannel> {
/// [`Context::create_emoji`]: ../struct.Context.html#method.create_emoji
/// [`Guild`]: ../../model/struct.Guild.html
/// [Manage Emojis]: ../../model/permissions/constant.MANAGE_EMOJIS.html
-pub fn create_emoji(guild_id: u64, map: Value) -> Result<Emoji> {
- let body = serde_json::to_string(&map)?;
+pub fn create_emoji(guild_id: u64, map: &Value) -> Result<Emoji> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdEmojis(guild_id),
post(body),
"/guilds/{}/emojis",
@@ -288,8 +288,8 @@ pub fn create_emoji(guild_id: u64, map: Value) -> Result<Emoji> {
/// [`Shard`]: ../gateway/struct.Shard.html
/// [US West Region]: ../../model/enum.Region.html#variant.UsWest
/// [whitelist]: https://discordapp.com/developers/docs/resources/guild#create-guild
-pub fn create_guild(map: Value) -> Result<PartialGuild> {
- let body = serde_json::to_string(&map)?;
+pub fn create_guild(map: &Value) -> Result<PartialGuild> {
+ let body = map.to_string();
let response = request!(Route::Guilds, post(body), "/guilds");
PartialGuild::decode(serde_json::from_reader(response)?)
@@ -305,8 +305,8 @@ pub fn create_guild(map: Value) -> Result<PartialGuild> {
/// [`Integration`]: ../../model/struct.Integration.html
/// [Manage Guild]: ../../model/permissions/constant.MANAGE_GUILD.html
/// [docs]: https://discordapp.com/developers/docs/resources/guild#create-guild-integration
-pub fn create_guild_integration(guild_id: u64, integration_id: u64, map: Value) -> Result<()> {
- let body = serde_json::to_string(&map)?;
+pub fn create_guild_integration(guild_id: u64, integration_id: u64, map: &Value) -> Result<()> {
+ let body = map.to_string();
verify(204, request!(Route::GuildsIdIntegrations(guild_id),
post(body),
@@ -327,8 +327,8 @@ pub fn create_guild_integration(guild_id: u64, integration_id: u64, map: Value)
/// [`RichInvite`]: ../../model/struct.RichInvite.html
/// [Create Invite]: ../../model/permissions/constant.CREATE_INVITE.html
/// [docs]: https://discordapp.com/developers/docs/resources/channel#create-channel-invite
-pub fn create_invite(channel_id: u64, map: Value) -> Result<RichInvite> {
- let body = serde_json::to_string(&map)?;
+pub fn create_invite(channel_id: u64, map: &Value) -> Result<RichInvite> {
+ let body = map.to_string();
let response = request!(Route::ChannelsIdInvites(channel_id),
post(body),
"/channels/{}/invites",
@@ -338,8 +338,8 @@ pub fn create_invite(channel_id: u64, map: Value) -> Result<RichInvite> {
}
/// Creates a permission override for a member or a role in a channel.
-pub fn create_permission(channel_id: u64, target_id: u64, map: Value) -> Result<()> {
- let body = serde_json::to_string(&map)?;
+pub fn create_permission(channel_id: u64, target_id: u64, map: &Value) -> Result<()> {
+ let body = map.to_string();
verify(204, request!(Route::ChannelsIdPermissionsOverwriteId(channel_id),
put(body),
@@ -349,8 +349,8 @@ pub fn create_permission(channel_id: u64, target_id: u64, map: Value) -> Result<
}
/// Creates a private channel with a user.
-pub fn create_private_channel(map: Value) -> Result<PrivateChannel> {
- let body = serde_json::to_string(&map)?;
+pub fn create_private_channel(map: &Value) -> Result<PrivateChannel> {
+ let body = map.to_string();
let response = request!(Route::UsersMeChannels,
post(body),
"/users/@me/channels");
@@ -361,7 +361,7 @@ pub fn create_private_channel(map: Value) -> Result<PrivateChannel> {
/// Reacts to a message.
pub fn create_reaction(channel_id: u64,
message_id: u64,
- reaction_type: ReactionType)
+ reaction_type: &ReactionType)
-> Result<()> {
verify(204, request!(Route::ChannelsIdMessagesIdReactionsUserIdType(channel_id),
put,
@@ -372,8 +372,8 @@ pub fn create_reaction(channel_id: u64,
}
/// Creates a role.
-pub fn create_role(guild_id: u64, map: Value) -> Result<Role> {
- let body = serde_json::to_string(&map)?;
+pub fn create_role(guild_id: u64, map: &Value) -> Result<Role> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdRoles(guild_id),
post(body),
"/guilds/{}/roles",
@@ -412,8 +412,8 @@ pub fn create_role(guild_id: u64, map: Value) -> Result<Role> {
/// ```
///
/// [`GuildChannel`]: ../../model/struct.GuildChannel.html
-pub fn create_webhook(channel_id: u64, map: Value) -> Result<Webhook> {
- let body = serde_json::to_string(&map)?;
+pub fn create_webhook(channel_id: u64, map: &Value) -> Result<Webhook> {
+ let body = map.to_string();
let response = request!(Route::ChannelsIdWebhooks(channel_id),
post(body),
"/channels/{}/webhooks",
@@ -478,8 +478,8 @@ pub fn delete_message(channel_id: u64, message_id: u64) -> Result<()> {
}
/// Deletes a bunch of messages, only works for bots.
-pub fn delete_messages(channel_id: u64, map: Value) -> Result<()> {
- let body = serde_json::to_string(&map)?;
+pub fn delete_messages(channel_id: u64, map: &Value) -> Result<()> {
+ let body = map.to_string();
verify(204, request!(Route::ChannelsIdMessagesBulkDelete(channel_id),
post(body),
@@ -526,7 +526,7 @@ pub fn delete_permission(channel_id: u64, target_id: u64) -> Result<()> {
pub fn delete_reaction(channel_id: u64,
message_id: u64,
user_id: Option<u64>,
- reaction_type: ReactionType)
+ reaction_type: &ReactionType)
-> Result<()> {
let user = user_id.map(|uid| uid.to_string()).unwrap_or_else(|| "@me".to_string());
@@ -599,8 +599,8 @@ pub fn delete_webhook_with_token(webhook_id: u64, token: &str) -> Result<()> {
}
/// Changes channel information.
-pub fn edit_channel(channel_id: u64, map: Value) -> Result<GuildChannel> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_channel(channel_id: u64, map: &Value) -> Result<GuildChannel> {
+ let body = map.to_string();
let response = request!(Route::ChannelsId(channel_id),
patch(body),
"/channels/{}",
@@ -610,8 +610,8 @@ pub fn edit_channel(channel_id: u64, map: Value) -> Result<GuildChannel> {
}
/// Changes emoji information.
-pub fn edit_emoji(guild_id: u64, emoji_id: u64, map: Value) -> Result<Emoji> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_emoji(guild_id: u64, emoji_id: u64, map: &Value) -> Result<Emoji> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdEmojisId(guild_id),
patch(body),
"/guilds/{}/emojis/{}",
@@ -622,8 +622,8 @@ pub fn edit_emoji(guild_id: u64, emoji_id: u64, map: Value) -> Result<Emoji> {
}
/// Changes guild information.
-pub fn edit_guild(guild_id: u64, map: Value) -> Result<PartialGuild> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_guild(guild_id: u64, map: &Value) -> Result<PartialGuild> {
+ let body = map.to_string();
let response = request!(Route::GuildsId(guild_id),
patch(body),
"/guilds/{}",
@@ -635,8 +635,8 @@ pub fn edit_guild(guild_id: u64, map: Value) -> Result<PartialGuild> {
/// Edits a [`Guild`]'s embed setting.
///
/// [`Guild`]: ../../model/struct.Guild.html
-pub fn edit_guild_embed(guild_id: u64, map: Value) -> Result<GuildEmbed> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_guild_embed(guild_id: u64, map: &Value) -> Result<GuildEmbed> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdEmbed(guild_id),
patch(body),
"/guilds/{}/embed",
@@ -646,8 +646,8 @@ pub fn edit_guild_embed(guild_id: u64, map: Value) -> Result<GuildEmbed> {
}
/// Does specific actions to a member.
-pub fn edit_member(guild_id: u64, user_id: u64, map: Value) -> Result<()> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_member(guild_id: u64, user_id: u64, map: &Value) -> Result<()> {
+ let body = map.to_string();
verify(204, request!(Route::GuildsIdMembersId(guild_id),
patch(body),
@@ -659,8 +659,8 @@ pub fn edit_member(guild_id: u64, user_id: u64, map: Value) -> Result<()> {
/// Edits a message by Id.
///
/// **Note**: Only the author of a message can modify it.
-pub fn edit_message(channel_id: u64, message_id: u64, map: Value) -> Result<Message> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_message(channel_id: u64, message_id: u64, map: &Value) -> Result<Message> {
+ let body = map.to_string();
let response = request!(Route::ChannelsIdMessagesId(LightMethod::Any, channel_id),
patch(body),
"/channels/{}/messages/{}",
@@ -677,7 +677,7 @@ pub fn edit_message(channel_id: u64, message_id: u64, map: Value) -> Result<Mess
/// [`Guild`]: ../../model/struct.Guild.html
pub fn edit_nickname(guild_id: u64, new_nickname: Option<&str>) -> Result<()> {
let map = ObjectBuilder::new().insert("nick", new_nickname).build();
- let body = serde_json::to_string(&map)?;
+ let body = map.to_string();
let response = request!(Route::GuildsIdMembersMeNick(guild_id),
patch(body),
"/guilds/{}/members/@me/nick",
@@ -687,8 +687,8 @@ pub fn edit_nickname(guild_id: u64, new_nickname: Option<&str>) -> Result<()> {
}
/// Changes a profile note.
-pub fn edit_note(user_id: u64, map: Value) -> Result<()> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_note(user_id: u64, map: &Value) -> Result<()> {
+ let body = map.to_string();
verify(204, request!(Route::None,
put(body),
@@ -708,8 +708,8 @@ pub fn edit_note(user_id: u64, map: Value) -> Result<()> {
/// **Note**: this token change may cause requests made between the actual token
/// change and when the token is internally changed to be invalid requests, as
/// the token may be outdated.
-pub fn edit_profile(map: Value) -> Result<CurrentUser> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_profile(map: &Value) -> Result<CurrentUser> {
+ let body = map.to_string();
let response = request!(Route::UsersMe, patch(body), "/users/@me");
let mut map: BTreeMap<String, Value> = serde_json::from_reader(response)?;
@@ -724,9 +724,9 @@ pub fn edit_profile(map: Value) -> Result<CurrentUser> {
}
/// Changes a role in a guild.
-pub fn edit_role(guild_id: u64, role_id: u64, map: Value)
+pub fn edit_role(guild_id: u64, role_id: u64, map: &Value)
-> Result<Role> {
- let body = serde_json::to_string(&map)?;
+ let body = map.to_string();
let response = request!(Route::GuildsIdRolesId(guild_id),
patch(body),
"/guilds/{}/roles/{}",
@@ -775,8 +775,8 @@ pub fn edit_role(guild_id: u64, role_id: u64, map: Value)
/// [`edit_webhook_with_token`]: fn.edit_webhook_with_token.html
// The tests are ignored, rather than no_run'd, due to rustdoc tests with
// external crates being incredibly messy and misleading in the end user's view.
-pub fn edit_webhook(webhook_id: u64, map: Value) -> Result<Webhook> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_webhook(webhook_id: u64, map: &Value) -> Result<Webhook> {
+ let body = map.to_string();
let response = request!(Route::WebhooksId,
patch(body),
"/webhooks/{}",
@@ -811,8 +811,8 @@ pub fn edit_webhook(webhook_id: u64, map: Value) -> Result<Webhook> {
/// ```
///
/// [`edit_webhook`]: fn.edit_webhook.html
-pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: Value) -> Result<Webhook> {
- let body = serde_json::to_string(&map)?;
+pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: &Value) -> Result<Webhook> {
+ let body = map.to_string();
let client = HyperClient::new();
let response = retry(|| client
.patch(&format!(api!("/webhooks/{}/{}"), webhook_id, token))
@@ -876,8 +876,8 @@ pub fn edit_webhook_with_token(webhook_id: u64, token: &str, map: Value) -> Resu
/// [`Channel`]: ../../model/enum.Channel.html
/// [`Message`]: ../../model/struct.Message.html
/// [Discord docs]: https://discordapp.com/developers/docs/resources/webhook#querystring-params
-pub fn execute_webhook(webhook_id: u64, token: &str, map: Value) -> Result<Message> {
- let body = serde_json::to_string(&map)?;
+pub fn execute_webhook(webhook_id: u64, token: &str, map: &Value) -> Result<Message> {
+ let body = map.to_string();
let client = HyperClient::new();
let response = retry(|| client
.post(&format!(api!("/webhooks/{}/{}"), webhook_id, token))
@@ -1097,8 +1097,8 @@ pub fn get_guild_members(guild_id: u64, limit: Option<u64>, after: Option<u64>)
}
/// Gets the amount of users that can be pruned.
-pub fn get_guild_prune_count(guild_id: u64, map: Value) -> Result<GuildPrune> {
- let body = serde_json::to_string(&map)?;
+pub fn get_guild_prune_count(guild_id: u64, map: &Value) -> Result<GuildPrune> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdPrune(guild_id),
get(body),
"/guilds/{}/prune",
@@ -1179,10 +1179,10 @@ pub fn get_guild_webhooks(guild_id: u64) -> Result<Vec<Webhook>> {
/// ```
///
/// [docs]: https://discordapp.com/developers/docs/resources/user#get-current-user-guilds
-pub fn get_guilds(target: GuildPagination, limit: u64) -> Result<Vec<GuildInfo>> {
+pub fn get_guilds(target: &GuildPagination, limit: u64) -> Result<Vec<GuildInfo>> {
let mut uri = format!("/users/@me/guilds?limit={}", limit);
- match target {
+ match *target {
GuildPagination::After(id) => {
write!(uri, "&after={}", id)?;
},
@@ -1234,7 +1234,7 @@ pub fn get_messages(channel_id: u64, query: &str)
query);
let client = HyperClient::new();
let response = request(Route::ChannelsIdMessages(channel_id),
- || client.get(&url))?;
+ || client.get(&url))?;
decode_array(serde_json::from_reader(response)?, Message::decode)
}
@@ -1252,7 +1252,7 @@ pub fn get_pins(channel_id: u64) -> Result<Vec<Message>> {
/// Gets user Ids based on their reaction to a message. This endpoint is dumb.
pub fn get_reaction_users(channel_id: u64,
message_id: u64,
- reaction_type: ReactionType,
+ reaction_type: &ReactionType,
limit: u8,
after: Option<u64>)
-> Result<Vec<User>> {
@@ -1512,22 +1512,15 @@ pub fn send_file<R: Read>(channel_id: u64,
request.write_stream("file", &mut file, Some(filename), None)?;
for (k, v) in map {
- let val = match v {
- Value::I64(v) => v.to_string(),
- Value::String(v) => v,
- Value::U64(v) => v.to_string(),
- _ => continue,
- };
-
- request.write_text(&k, val)?;
+ request.write_text(&k, v.to_string())?;
}
Message::decode(serde_json::from_reader(request.send()?)?)
}
/// Sends a message to a channel.
-pub fn send_message(channel_id: u64, map: Value) -> Result<Message> {
- let body = serde_json::to_string(&map)?;
+pub fn send_message(channel_id: u64, map: &Value) -> Result<Message> {
+ let body = map.to_string();
let response = request!(Route::ChannelsIdMessages(channel_id),
post(body),
"/channels/{}/messages",
@@ -1573,8 +1566,8 @@ pub fn remove_member_role(guild_id: u64, user_id: u64, role_id: u64) -> Result<(
}
/// Starts removing some members from a guild based on the last time they've been online.
-pub fn start_guild_prune(guild_id: u64, map: Value) -> Result<GuildPrune> {
- let body = serde_json::to_string(&map)?;
+pub fn start_guild_prune(guild_id: u64, map: &Value) -> Result<GuildPrune> {
+ let body = map.to_string();
let response = request!(Route::GuildsIdPrune(guild_id),
post(body),
"/guilds/{}/prune",
diff --git a/src/client/rest/ratelimiting.rs b/src/client/rest/ratelimiting.rs
index f232759..2f252ac 100644
--- a/src/client/rest/ratelimiting.rs
+++ b/src/client/rest/ratelimiting.rs
@@ -38,6 +38,7 @@
//! differentiating between different ratelimits.
//!
//! [Taken from]: https://discordapp.com/developers/docs/topics/rate-limits#rate-limits
+#![allow(zero_ptr)]
use hyper::client::{RequestBuilder, Response};
use hyper::header::Headers;
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