diff options
| author | Austin Hellyer <[email protected]> | 2017-01-03 20:37:33 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2017-01-04 11:58:34 -0800 |
| commit | 5a1f7c1cf9f4b5c27719d5ed6a9e0bb2ff292893 (patch) | |
| tree | 7ad210faf4d5f2eff227058af63c025180141561 /src/client | |
| parent | Simplify Context::get_reaction_users (diff) | |
| download | serenity-5a1f7c1cf9f4b5c27719d5ed6a9e0bb2ff292893.tar.xz serenity-5a1f7c1cf9f4b5c27719d5ed6a9e0bb2ff292893.zip | |
Simplify a small bit of Context
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/context.rs | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index b99dcfc..1359075 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -634,9 +634,9 @@ impl Context { return Err(Error::Client(ClientError::InvalidOperationAsUser)) } - let ids: Vec<u64> = message_ids.into_iter() + let ids = message_ids.into_iter() .map(|message_id| message_id.0) - .collect(); + .collect::<Vec<u64>>(); let map = ObjectBuilder::new() .insert("messages", ids) @@ -1070,9 +1070,7 @@ impl Context { #[cfg(feature="cache")] { - let cache = CACHE.read().unwrap(); - - if let Some(guild) = cache.get_guild(guild_id) { + if let Some(guild) = CACHE.read().unwrap().get_guild(guild_id) { return Ok(guild.channels.clone()); } } @@ -1266,25 +1264,20 @@ impl Context { /// [Read Message History]: ../model/permission/constant.READ_MESSAGE_HISTORY.html pub fn get_messages<C, F>(&self, channel_id: C, f: F) -> Result<Vec<Message>> where C: Into<ChannelId>, F: FnOnce(GetMessages) -> GetMessages { - let query = { - let mut map = f(GetMessages::default()).0; - let mut query = String::new(); - write!(query, "?limit={}", map.remove("limit").unwrap_or(50))?; + let mut map = f(GetMessages::default()).0; + let mut query = format!("?limit={}", map.remove("limit").unwrap_or(50)); - if let Some(after) = map.remove("after") { - write!(query, "&after={}", after)?; - } - - if let Some(around) = map.remove("around") { - write!(query, "&around={}", around)?; - } + if let Some(after) = map.remove("after") { + write!(query, "&after={}", after)?; + } - if let Some(before) = map.remove("before") { - write!(query, "&before={}", before)?; - } + if let Some(around) = map.remove("around") { + write!(query, "&around={}", around)?; + } - query - }; + if let Some(before) = map.remove("before") { + write!(query, "&before={}", before)?; + } rest::get_messages(channel_id.into().0, &query) } |