diff options
| author | acdenisSK <[email protected]> | 2017-08-24 15:26:49 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-08-24 16:36:01 +0200 |
| commit | b3a5bc89ad1c09290fb1c15ca3b36fe17c3796f3 (patch) | |
| tree | 315e16f7b252d22b5f832302e722a85c9e6a9b6e /src/http/ratelimiting.rs | |
| parent | Allow FromStr for User to use REST (#147) (diff) | |
| download | serenity-b3a5bc89ad1c09290fb1c15ca3b36fe17c3796f3.tar.xz serenity-b3a5bc89ad1c09290fb1c15ca3b36fe17c3796f3.zip | |
Revamp `RwLock` usage in the lib
Also not quite sure if they goofed rustfmt or something, but its changes it did were a bit bizarre.
Diffstat (limited to 'src/http/ratelimiting.rs')
| -rw-r--r-- | src/http/ratelimiting.rs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/http/ratelimiting.rs b/src/http/ratelimiting.rs index 039f15d..52762f5 100644 --- a/src/http/ratelimiting.rs +++ b/src/http/ratelimiting.rs @@ -47,7 +47,7 @@ use hyper::status::StatusCode; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::time::Duration; -use std::{i64, str, thread}; +use std::{str, thread, i64}; use super::{HttpError, LightMethod}; use internal::prelude::*; @@ -399,15 +399,16 @@ pub(crate) fn perform<'a, F>(route: Route, f: F) -> Result<Response> let redo = if response.headers.get_raw("x-ratelimit-global").is_some() { let _ = GLOBAL.lock().expect("global route lock poisoned"); - Ok(if let Some(retry_after) = - parse_header(&response.headers, "retry-after")? { - debug!("Ratelimited on route {:?} for {:?}ms", route, retry_after); - thread::sleep(Duration::from_millis(retry_after as u64)); + Ok( + if let Some(retry_after) = parse_header(&response.headers, "retry-after")? { + debug!("Ratelimited on route {:?} for {:?}ms", route, retry_after); + thread::sleep(Duration::from_millis(retry_after as u64)); - true - } else { - false - }) + true + } else { + false + }, + ) } else { lock.post_hook(&response, &route) }; @@ -505,16 +506,12 @@ impl RateLimit { fn parse_header(headers: &Headers, header: &str) -> Result<Option<i64>> { match headers.get_raw(header) { - Some(header) => { - match str::from_utf8(&header[0]) { - Ok(v) => { - match v.parse::<i64>() { - Ok(v) => Ok(Some(v)), - Err(_) => Err(Error::Http(HttpError::RateLimitI64)), - } - }, - Err(_) => Err(Error::Http(HttpError::RateLimitUtf8)), - } + Some(header) => match str::from_utf8(&header[0]) { + Ok(v) => match v.parse::<i64>() { + Ok(v) => Ok(Some(v)), + Err(_) => Err(Error::Http(HttpError::RateLimitI64)), + }, + Err(_) => Err(Error::Http(HttpError::RateLimitUtf8)), }, None => Ok(None), } |