clean code
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nyyu 2021-05-10 10:40:27 +02:00
parent 411b59071e
commit c2ff1b9bc4
4 changed files with 10 additions and 13 deletions

View file

@ -5,7 +5,7 @@ use log::{error, info};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::Path;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct ItemSet { struct ItemSet {
@ -57,7 +57,7 @@ pub trait DataSource {
&self, &self,
champ: &ChampInfo, champ: &ChampInfo,
positions: &[String], positions: &[String],
path: &PathBuf, path: &Path,
client: &ureq::Agent, client: &ureq::Agent,
) { ) {
info!( info!(

View file

@ -115,10 +115,7 @@ fn get_auth_token() -> Option<String> {
None => return None, None => return None,
}; };
bundle = (&bundle[(q_position + 1)..]).to_string(); bundle = (&bundle[(q_position + 1)..]).to_string();
match bundle.find('"') { bundle.find('"').map(|position| (&bundle[..position]).to_string())
Some(position) => Some((&bundle[..position]).to_string()),
None => None,
}
} }
impl KBDataSource { impl KBDataSource {

View file

@ -11,7 +11,7 @@ use std::io;
use std::io::Error; use std::io::Error;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::io::ErrorKind; use std::io::ErrorKind;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use std::time::Instant; use std::time::Instant;
use std::{fs, thread, time}; use std::{fs, thread, time};
use time::Duration; use time::Duration;
@ -128,7 +128,7 @@ fn execute_data_source(
data_source: &(dyn DataSource + Sync + Send), data_source: &(dyn DataSource + Sync + Send),
client: &ureq::Agent, client: &ureq::Agent,
champion: &Champion, champion: &Champion,
lol_champs_dir: &PathBuf, lol_champs_dir: &Path,
) { ) {
let champs = data_source.get_champs_with_positions(&client, &champion); let champs = data_source.get_champs_with_positions(&client, &champion);
@ -168,7 +168,7 @@ fn get_and_write_item_set(
data_source: &(dyn DataSource + Sync + Send), data_source: &(dyn DataSource + Sync + Send),
client: &ureq::Agent, client: &ureq::Agent,
champion: &Champion, champion: &Champion,
lol_champs_dir: &PathBuf, lol_champs_dir: &Path,
id: u32, id: u32,
positions: &[String], positions: &[String],
) { ) {

View file

@ -36,9 +36,9 @@ impl DataSource for MSDataSource {
let role = let role =
&page[p + page[p..].find('/').unwrap() + 1..p + page[p..].find('"').unwrap()]; &page[p + page[p..].find('/').unwrap() + 1..p + page[p..].find('"').unwrap()];
let k = p + &page[p..].find("data-search-terms-like=\"").unwrap() + 24; let k = p + page[p..].find("data-search-terms-like=\"").unwrap() + 24;
let pipe = k + &page[k..].find("|").unwrap() + 1; let pipe = k + page[k..].find('|').unwrap() + 1;
let key = &page[pipe..pipe + &page[pipe..].find('"').unwrap()]; let key = &page[pipe..pipe + page[pipe..].find('"').unwrap()];
let id = champion.data.get(key).unwrap().key.parse::<u32>().unwrap(); let id = champion.data.get(key).unwrap().key.parse::<u32>().unwrap();
@ -82,7 +82,7 @@ impl DataSource for MSDataSource {
let mut pos: Option<usize> = page.find("/item/"); let mut pos: Option<usize> = page.find("/item/");
while let Some(mut p) = pos { while let Some(mut p) = pos {
p += 6; p += 6;
let i = &page[p..p + &page[p..].find('.').unwrap()]; let i = &page[p..p + page[p..].find('.').unwrap()];
items.push(i); items.push(i);