diff --git a/Cargo.lock b/Cargo.lock index ed30859..d35e0c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,6 @@ name = "cggitem_sets" version = "1.0.0" dependencies = [ "indexmap", - "lazy_static", "log", "rayon", "serde", @@ -65,12 +64,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "chunked_transfer" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cca491388666e04d7248af3f60f0c40cfb0991c72205595d7c396e3510207d1a" - [[package]] name = "colored" version = "2.0.0" @@ -511,12 +504,11 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "ureq" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f" +checksum = "733b5ad78377302af52c0dbcb2623d78fe50e4b3bf215948ff29e9ee031d8566" dependencies = [ "base64", - "chunked_transfer", "flate2", "log", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index a37f55a..0cf28e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,15 +7,14 @@ version = "1.0.0" include = ["src/**/*"] [dependencies] -indexmap = {version = "1.8", features = ["serde-1", "rayon"]} -lazy_static = "1.4" +indexmap = {version = "1.9", features = ["serde-1", "rayon"]} log = "0.4" -rayon = "1.5" +rayon = "1.6" serde = "1.0" serde_derive = "1.0" serde_json = {version = "1.0", features = ["preserve_order"]} simple_logger = "4.0" -ureq = {version = "2.4", features = ["json"]} +ureq = {version = "2.6", features = ["json"]} [target.'cfg(windows)'.dependencies] winreg = "0.10" diff --git a/src/cgg_data_source.rs b/src/cgg_data_source.rs index fbda60d..0aba79f 100644 --- a/src/cgg_data_source.rs +++ b/src/cgg_data_source.rs @@ -1,5 +1,4 @@ use indexmap::IndexMap; -use lazy_static::lazy_static; use log::error; use serde_derive::Deserialize; use serde_json::{json, Value}; @@ -52,13 +51,17 @@ struct Build { games: u32, } -lazy_static! { - static ref CHAMPIONS_REPORT: Mutex> = Mutex::new(Vec::new()); +pub struct CGGDataSource { + champions_report: Mutex>, } -pub struct CGGDataSource; - impl CGGDataSource { + pub fn new() -> CGGDataSource { + Self { + champions_report: Mutex::new(Vec::new()), + } + } + fn make_item_set(&self, build: &Build, label: &str) -> Value { json!({ "items": build.build.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::>(), @@ -119,7 +122,7 @@ impl DataSource for CGGDataSource { } for report in datas.lol.champions_report { - CHAMPIONS_REPORT.lock().unwrap().push(report); + self.champions_report.lock().unwrap().push(report); } } Err(e) => error!("Error retrieving data: {}", e), @@ -136,7 +139,7 @@ impl DataSource for CGGDataSource { let mut data = vec![]; for position in positions { let mut some_champ: Option<&ChampionReport> = None; - let reports = CHAMPIONS_REPORT.lock().unwrap(); + let reports = self.champions_report.lock().unwrap(); for champion in reports.iter() { if champion.champion_id.to_string() == champ.key && champion.role == *position { some_champ = Some(champion); diff --git a/src/kb_data_source.rs b/src/kb_data_source.rs index c0af61e..d8d3d5d 100644 --- a/src/kb_data_source.rs +++ b/src/kb_data_source.rs @@ -3,7 +3,6 @@ use crate::ChampInfo; use crate::Champion as ChampionLoL; use crate::USER_AGENT_VALUE; use indexmap::IndexMap; -use lazy_static::lazy_static; use serde_derive::Deserialize; use serde_json::{json, Value}; use std::time::Duration; @@ -110,25 +109,22 @@ fn get_auth_token() -> Option { Some(position) => position, None => return None, }; - bundle = (&bundle[(auth_position + 13)..]).to_string(); + bundle = bundle[(auth_position + 13)..].to_string(); let q_position = match bundle.find('"') { Some(position) => position, None => return None, }; - bundle = (&bundle[(q_position + 1)..]).to_string(); + bundle = bundle[(q_position + 1)..].to_string(); bundle .find('"') - .map(|position| (&bundle[..position]).to_string()) + .map(|position| bundle[..position].to_string()) } impl KBDataSource { - pub fn new() -> &'static KBDataSource { - lazy_static! { - static ref DATASOURCE: KBDataSource = KBDataSource { - token: get_auth_token(), - }; + pub fn new() -> KBDataSource { + Self { + token: get_auth_token(), } - &DATASOURCE } fn get_champion_response(&self, client: &ureq::Agent) -> Option { diff --git a/src/main.rs b/src/main.rs index e31a096..fbdbdde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use std::io; use std::io::Error; #[cfg(target_os = "windows")] use std::io::ErrorKind; +use std::ops::Deref; use std::path::{Path, PathBuf}; use std::time::Instant; use std::{fs, thread, time}; @@ -101,15 +102,15 @@ fn main() -> Result<(), Box> { .into_json()?; info!("LoL numbers of champs: {}", champion.data.len()); - let data_sources: [&'static (dyn DataSource + Sync + Send); 4] = [ - &PBDataSource, - &CGGDataSource, - KBDataSource::new(), - &MSDataSource, + let data_sources: Vec> = vec![ + Box::new(PBDataSource), + Box::new(CGGDataSource::new()), + Box::new(KBDataSource::new()), + Box::new(MSDataSource), ]; data_sources.par_iter().for_each(|data_source| { let init = Instant::now(); - execute_data_source(*data_source, &client, &champion, &lol_champs_dir); + execute_data_source(data_source.deref(), &client, &champion, &lol_champs_dir); info!( "{}: done in {}s", data_source.get_alias(), diff --git a/src/ms_data_source.rs b/src/ms_data_source.rs index db9ca00..b4cfe6b 100644 --- a/src/ms_data_source.rs +++ b/src/ms_data_source.rs @@ -40,7 +40,7 @@ impl DataSource for MSDataSource { let k = p + page[p..].find("data-search-terms-like=").unwrap() + 23; let pipe = k + page[k..].find('|').unwrap() + 1; - let key = &page[pipe..pipe + page[pipe..].find(' ').unwrap()].replace("\"", ""); + let key = &page[pipe..pipe + page[pipe..].find(' ').unwrap()].replace('\"', ""); let id = champion.data.get(key).unwrap().key.parse::().unwrap(); @@ -82,10 +82,10 @@ impl DataSource for MSDataSource { let patch = &page[pos + 6..pos + 11]; pos = page.find("Win Rate:").unwrap(); - let win_rate: f32 = (&page[pos + 26..pos + 31]).parse().unwrap(); + let win_rate: f32 = page[pos + 26..pos + 31].parse().unwrap(); pos = page.find("KDA:").unwrap(); - let kda: f32 = (&page[pos + 21..pos + 25]).parse().unwrap(); + let kda: f32 = page[pos + 21..pos + 25].parse().unwrap(); let mut items = vec![];