From 6947fbe05abfff8b5efb6b06068567ac0238c3a0 Mon Sep 17 00:00:00 2001 From: nyyu Date: Sat, 9 Jun 2018 11:10:49 +0200 Subject: [PATCH] clean code --- src/main.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 871f638..0cddd31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -179,8 +179,11 @@ fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option< )) .send() .unwrap(); - if req.status() == reqwest::StatusCode::Ok { - serde_json::from_str(&find_champ_data(&req.text().unwrap())).unwrap() + if req.status().is_success() { + lazy_static! { + static ref RE: Regex = Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap(); + } + serde_json::from_str(&RE.captures(&req.text().unwrap())?[1]).unwrap() } else { None } @@ -256,13 +259,6 @@ fn write_item_set(id: &str, pos: &str, ver: &str, path: &PathBuf, client: &reqwe } } -fn find_champ_data(text: &str) -> String { - lazy_static! { - static ref RE: Regex = Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap(); - } - RE.captures(text).unwrap()[1].to_string() -} - fn lol_champ_dir() -> Result { let hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE); let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS")?;