Use i32 instead of usize

This commit is contained in:
blank X 2020-12-02 22:34:42 +07:00
parent b4d07aa1ae
commit 829e8ad36c
4 changed files with 17 additions and 17 deletions

View File

@ -42,7 +42,7 @@ pub async fn run(args: env::Args) {
_ => panic!("Got a weird error while creating dir: {}", err)
}
};
let mut page_num: usize = 1;
let mut page_num: i32 = 1;
for page in sauce_info.images.pages {
let file_ext = match page.t.as_str() {
"j" => ".jpg",

View File

@ -16,7 +16,7 @@ pub async fn run(args: env::Args) {
exit(1);
}
let client = reqwest::Client::new();
let mut handles: Vec<JoinHandle<(structs::GalleryInfo, usize)>> = Vec::with_capacity(sauces.len());
let mut handles: Vec<JoinHandle<(structs::GalleryInfo, i32)>> = Vec::with_capacity(sauces.len());
for sauce in sauces {
let cloned_client = client.clone();
handles.push(tokio::spawn(async move {

View File

@ -10,8 +10,8 @@ pub struct GalleryTitleInfo {
#[derive(Deserialize, Debug)]
pub struct GalleryImageInfo {
pub t: String,
pub w: usize,
pub h: usize
pub w: i32,
pub h: i32
}
#[derive(Deserialize, Debug)]
@ -23,24 +23,24 @@ pub struct GalleryImagesInfo {
#[derive(Deserialize, Debug)]
pub struct GalleryTagInfo {
pub id: usize,
pub id: i32,
pub r#type: String,
pub name: String,
pub url: String,
pub count: usize
pub count: i32
}
#[derive(Deserialize, Debug)]
pub struct GalleryInfoSuccess {
pub id: usize,
pub id: i32,
pub media_id: String,
pub title: GalleryTitleInfo,
pub images: GalleryImagesInfo,
pub scanlator: String,
pub upload_date: usize,
pub upload_date: i32,
pub tags: Vec<GalleryTagInfo>,
pub num_pages: usize,
pub num_favorites: usize
pub num_pages: i32,
pub num_favorites: i32
}
#[derive(Deserialize, Debug)]
@ -58,6 +58,6 @@ pub enum GalleryInfo {
#[derive(Deserialize, Debug)]
pub struct SearchInfo {
pub result: Vec<GalleryInfoSuccess>,
pub num_pages: usize,
pub per_page: usize
pub num_pages: i32,
pub per_page: i32
}

View File

@ -11,13 +11,13 @@ extern crate reqwest;
fn fix_gallery(body: &mut serde_json::Value) -> Result<(), serde_json::Error> {
if body["id"].is_string() {
body["id"] = serde_json::json!(
body["id"].as_str().unwrap().parse::<usize>().unwrap()
body["id"].as_str().unwrap().parse::<i32>().unwrap()
);
}
Ok(())
}
pub async fn get_sauce_info(client: reqwest::Client, sauce: usize) -> Result<structs::GalleryInfo, reqwest::Error> {
pub async fn get_sauce_info(client: reqwest::Client, sauce: i32) -> Result<structs::GalleryInfo, reqwest::Error> {
let mut uri = String::from("https://nhentai.net/api/gallery/");
uri.push_str(&sauce.to_string());
let resp = client.get(&uri)
@ -56,10 +56,10 @@ pub async fn download_file(client: reqwest::Client, url: &str, file_name: &str)
Ok(())
}
pub fn get_arg_sauces(args: env::Args) -> Result<Vec<usize>, String> {
let mut sauces: Vec<usize> = Vec::new();
pub fn get_arg_sauces(args: env::Args) -> Result<Vec<i32>, String> {
let mut sauces: Vec<i32> = Vec::new();
for sauce in args {
let sauce: usize = match sauce.parse() {
let sauce: i32 = match sauce.parse() {
Ok(sauce) => sauce,
Err(_) => {
return Err(format!("{} is not a number/sauce", sauce));