Skip to content

Commit

Permalink
change to unwrap_or
Browse files Browse the repository at this point in the history
  • Loading branch information
syrflover committed Jan 22, 2024
1 parent d833dc0 commit 23e66ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ itertools = "0.10"
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tap = "1.0"
thiserror = "1.0"
tracing = "0.1"

Expand Down
16 changes: 8 additions & 8 deletions src/gallery.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use reqwest::{Method, StatusCode};
use tap::Tap;

use crate::{model, network::http::request};

Expand Down Expand Up @@ -100,9 +101,9 @@ mod sealed {

impl From<File> for model::File {
fn from(file: File) -> Self {
let has_webp = file.haswebp.right_or_else(|x| x.parse().unwrap_or(0)) == 1;
let has_avif = file.hasavif.right_or_else(|x| x.parse().unwrap_or(0)) == 1;
let has_jxl = file.hasjxl.right_or_else(|x| x.parse().unwrap_or(0)) == 1;
let has_webp = file.haswebp.right_or_else(|x| x.parse().unwrap_or(0)) == 1_u8;
let has_avif = file.hasavif.right_or_else(|x| x.parse().unwrap_or(0)) == 1_u8;
let has_jxl = file.hasjxl.right_or_else(|x| x.parse().unwrap_or(0)) == 1_u8;

Self {
has_webp,
Expand Down Expand Up @@ -154,10 +155,8 @@ mod sealed {

impl From<Tag> for model::Tag {
fn from(x: Tag) -> Self {
// why use .unwrap()?
// breaking change, if this value is not 0 and 1
let is_female = x.female.right_or_else(|x| x.parse().unwrap()) == 1;
let is_male = x.male.right_or_else(|x| x.parse().unwrap()) == 1;
let is_female = x.female.right_or_else(|x| x.parse().unwrap_or(0)) == 1_u8;
let is_male = x.male.right_or_else(|x| x.parse().unwrap_or(0)) == 1_u8;

let kind = if is_female {
model::TagKind::Female
Expand Down Expand Up @@ -243,9 +242,10 @@ pub async fn parse(id: u32) -> crate::Result<model::Gallery> {

let gallery: model::Gallery = serde_json::from_str::<sealed::Gallery>(x)
.map_err(|err| Error::DeserializeGallery(txt, err))?
.tap(|x| tracing::debug!("{x:?}"))
.try_into()?;

tracing::debug!("{gallery:#?}");
tracing::debug!("{gallery:?}");
tracing::debug!("page = {}", gallery.files.len());

Ok(gallery)
Expand Down

0 comments on commit 23e66ed

Please sign in to comment.