diff options
| author | acdenisSK <[email protected]> | 2017-07-29 22:53:50 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-29 22:53:50 +0200 |
| commit | 0d6965f647396c84b2570e92b63244c3afaea863 (patch) | |
| tree | 497cb26d44af5deca9afbe5ef9395d27aa3c9a8d /src | |
| parent | Fix imports (diff) | |
| download | serenity-0d6965f647396c84b2570e92b63244c3afaea863.tar.xz serenity-0d6965f647396c84b2570e92b63244c3afaea863.zip | |
Remove a few clones
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/mod.rs | 11 | ||||
| -rw-r--r-- | src/framework/command.rs | 8 | ||||
| -rw-r--r-- | src/framework/mod.rs | 2 | ||||
| -rw-r--r-- | src/http/mod.rs | 2 | ||||
| -rw-r--r-- | src/http/ratelimiting.rs | 3 | ||||
| -rw-r--r-- | src/internal/ws_impl.rs | 13 | ||||
| -rw-r--r-- | src/utils/message_builder.rs | 14 |
7 files changed, 26 insertions, 27 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index 996b943..f5382e2 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -803,12 +803,13 @@ fn boot_shard(info: &BootInfo) -> Result<Shard> { // After three attempts, start re-retrieving the gateway URL. Before that, // use the cached one. for attempt_number in 1..3u64 { + let BootInfo { ref gateway_url, ref token, shard_info } = *info; // If we've tried over 3 times so far, get a new gateway URL. // // If doing so fails, count this as a boot attempt. if attempt_number > 3 { match http::get_gateway() { - Ok(g) => *info.gateway_url.lock().unwrap() = g.url, + Ok(g) => *gateway_url.lock().unwrap() = g.url, Err(why) => { warn!("Failed to retrieve gateway URL: {:?}", why); @@ -819,14 +820,14 @@ fn boot_shard(info: &BootInfo) -> Result<Shard> { } let attempt = Shard::new( - info.gateway_url.clone(), - info.token.clone(), - info.shard_info, + gateway_url.clone(), + token.clone(), + shard_info, ); match attempt { Ok(shard) => { - info!("Successfully booted shard: {:?}", info.shard_info); + info!("Successfully booted shard: {:?}", shard_info); return Ok(shard); }, diff --git a/src/framework/command.rs b/src/framework/command.rs index 4e338d4..19b6756 100644 --- a/src/framework/command.rs +++ b/src/framework/command.rs @@ -104,15 +104,15 @@ pub fn positions(ctx: &mut Context, msg: &Message, conf: &Configuration) -> Opti positions.push(x.len()); } } else { - for n in conf.prefixes.clone() { - if msg.content.starts_with(&n) { + for n in &conf.prefixes { + if msg.content.starts_with(n) { positions.push(n.len()); } } } } else { - for n in conf.prefixes.clone() { - if msg.content.starts_with(&n) { + for n in &conf.prefixes { + if msg.content.starts_with(n) { positions.push(n.len()); } } diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 14533b5..ccebfd4 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -682,7 +682,7 @@ impl BuiltinFramework { if let Some(ref prefix) = group.prefix { for v in &cmd.aliases { group.commands.insert( - format!("{} {}", prefix, v.to_owned()), + format!("{} {}", prefix, v), CommandOrAlias::Alias(format!("{} {}", prefix, name)), ); } diff --git a/src/http/mod.rs b/src/http/mod.rs index 0efea78..7692961 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1658,7 +1658,7 @@ pub fn send_files<'a, T>(channel_id: u64, files: Vec<T>, map: JsonMap) -> Result .set(header::UserAgent(constants::USER_AGENT.to_owned())); let mut request = Multipart::from_request(request)?; - let mut file_num = String::from("0".to_owned()); + let mut file_num = "0".to_owned(); for file in files { match file.into() { diff --git a/src/http/ratelimiting.rs b/src/http/ratelimiting.rs index f0eb8fc..dad5f7e 100644 --- a/src/http/ratelimiting.rs +++ b/src/http/ratelimiting.rs @@ -370,8 +370,7 @@ pub(crate) fn perform<'a, F>(route: Route, f: F) -> Result<Response> remaining: i64::MAX, reset: i64::MAX, })) - }) - .clone(); + }).clone(); let mut lock = bucket.lock().unwrap(); lock.pre_hook(&route); diff --git a/src/internal/ws_impl.rs b/src/internal/ws_impl.rs index 7aedb28..b20f0a6 100644 --- a/src/internal/ws_impl.rs +++ b/src/internal/ws_impl.rs @@ -19,11 +19,6 @@ impl ReceiverExt for WsClient<TlsStream<TcpStream>> { where F: FnOnce(Value) -> Result<T> { let message = self.recv_message()?; - if let OwnedMessage::Ping(ref x) = message { - self.send_message(&OwnedMessage::Pong(x.clone())) - .map_err(Error::from)?; - } - let res = match message { OwnedMessage::Binary(bytes) => { let value = serde_json::from_reader(ZlibDecoder::new(&bytes[..]))?; @@ -46,7 +41,13 @@ impl ReceiverExt for WsClient<TlsStream<TcpStream>> { why })) }, - OwnedMessage::Ping(..) | OwnedMessage::Pong(..) => None, + OwnedMessage::Ping(x) => { + self.send_message(&OwnedMessage::Pong(x)) + .map_err(Error::from)?; + + None + }, + OwnedMessage::Pong(_) => None, }; res.unwrap() diff --git a/src/utils/message_builder.rs b/src/utils/message_builder.rs index 8fd26e9..930b018 100644 --- a/src/utils/message_builder.rs +++ b/src/utils/message_builder.rs @@ -757,11 +757,10 @@ pub struct Content { impl<T: ToString> Add<T> for Content { type Output = Content; - fn add(self, rhs: T) -> Content { - let mut nc = self.clone(); - nc.inner = nc.inner + &rhs.to_string(); + fn add(mut self, rhs: T) -> Content { + self.inner = self.inner + &rhs.to_string(); - nc + self } } @@ -779,11 +778,10 @@ impl<T: ToString> Add<T> for ContentModifier { impl Add<ContentModifier> for Content { type Output = Content; - fn add(self, rhs: ContentModifier) -> Content { - let mut nc = self.clone(); - nc.apply(&rhs); + fn add(mut self, rhs: ContentModifier) -> Content { + self.apply(&rhs); - nc + self } } |