forked from mirror/Riven
1
0
Fork 0

cleaning up unuseds

users/mingwei/surf
Mingwei Samuel 2019-10-17 16:31:06 -07:00
parent ee75f75e0c
commit 2d105529b4
6 changed files with 16 additions and 35 deletions

View File

@ -1,5 +1,3 @@
#![allow(dead_code)] // TODO REMOVE
pub mod consts;
mod riot_api_config;
@ -16,12 +14,12 @@ mod tests {
use tokio::runtime::Runtime;
use super::*;
const api_key: &'static str = "RGAPI-nothinghereowo";
const API_KEY: &'static str = "RGAPI-nothinghereowo";
#[test]
fn it_works() {
let rt = Runtime::new().unwrap();
let riot_api = RiotApi::with_key(api_key);
let riot_api = RiotApi::with_key(API_KEY);
// https://na1.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw
let my_future = riot_api.get::<u32>("asdf", consts::Region::NA,

View File

@ -19,7 +19,6 @@ pub struct RateLimit {
// Buckets for this rate limit (synchronized).
// Almost always read, written only when rate limit rates are updated
// from API response.
// TODO: Question of writer starvation.
buckets: RwLock<Vec<VectorTokenBucket>>,
// Set to when we can retry if a retry-after header is received.
retry_after: Option<Instant>,

View File

@ -106,12 +106,6 @@ impl<'a> RegionalRequester<'a> {
panic!("FAILED AFTER {} ATTEMPTS!", attempts);
}
pub fn get2<T: 'a + serde::de::DeserializeOwned>(&'a self, method_id: &'a str, region: &'a Region<'_>, relative_url: &'a str,
query: &'a [(&'a str, &'a str)]) -> impl Future<Output = Result<Option<T>, reqwest::Error>> + 'a
{
self.get(method_id, region, relative_url, query)
}
fn is_none_status_code(status: &StatusCode) -> bool {
Self::NONE_STATUS_CODES.contains(&status.as_u16())
}
@ -120,9 +114,4 @@ impl<'a> RegionalRequester<'a> {
#[cfg(test)]
mod tests {
use super::*;
fn send_sync() {
fn is_send_sync<T: Send + Sync>() {}
is_send_sync::<RegionalRequester>();
}
}

View File

@ -21,7 +21,7 @@ pub struct RequesterManager<'a> {
impl<'a> RequesterManager<'a> {
pub fn new(riot_api_config: RiotApiConfig<'a>) -> Self {
// TODO client.
// TODO configure client.
let client = Client::new();
Self {
riot_api_config: riot_api_config,
@ -34,7 +34,7 @@ impl<'a> RequesterManager<'a> {
&'a self, method_id: &'a str, region: &'a Region<'a>, relative_url: &'_ str,
query: &[(&'_ str, &'_ str)]) -> Result<Option<T>, reqwest::Error>
{
// TODO: max concurrent requests?
// TODO: max concurrent requests? Or can configure client?
let regional_requester = self.regional_requesters
.get_or_insert_with(region, || RegionalRequester::new(&self.riot_api_config, &self.client));
regional_requester.get(method_id, region, relative_url, query).await

View File

@ -97,13 +97,8 @@ impl TokenBucket for VectorTokenBucket {
mod tests {
use super::*;
fn send_sync() {
fn is_send_sync<T: Send + Sync>() {}
is_send_sync::<VectorTokenBucket>();
}
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
// #[test]
// fn it_works() {
// assert_eq!(2 + 2, 4);
// }
}

View File

@ -17,14 +17,14 @@ impl<K: Hash + Eq, V> InsertOnlyCHashMap<K, V> {
}
}
#[inline]
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<Arc<V>>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.base.lock().get(key).map(|v| Arc::clone(v))
}
// #[inline]
// pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<Arc<V>>
// where
// K: Borrow<Q>,
// Q: Hash + Eq,
// {
// self.base.lock().get(key).map(|v| Arc::clone(v))
// }
#[inline]
pub fn get_or_insert_with<F: FnOnce() -> V>(&self, key: K, default: F) -> Arc<V>