diff --git a/src/jnovel/mod.rs b/src/jnovel/mod.rs index 3e19ac6..419f3ac 100644 --- a/src/jnovel/mod.rs +++ b/src/jnovel/mod.rs @@ -95,20 +95,19 @@ impl PartInfo { pub(crate) fn is_no_parts(&self) -> bool { !self.is_parts() } + + pub(crate) fn as_u8(&self) -> u8 { + match self { + Part(number) => *number, + NoParts => 0, + } + } } impl PartialEq for PartInfo { fn eq(&self, other: &Self) -> bool { - let self_numeric = match self { - Part(number) => number, - NoParts => &0, - }; - - let other_numeric = match other { - Part(number) => number, - NoParts => &0, - }; - + let self_numeric = self.as_u8(); + let other_numeric = other.as_u8(); self_numeric == other_numeric } } @@ -121,15 +120,8 @@ impl PartialOrd for PartInfo { } fn lt(&self, other: &Self) -> bool { - let self_numeric = match self { - Part(number) => number, - NoParts => &0, - }; - - let other_numeric = match other { - Part(number) => number, - NoParts => &0, - }; + let self_numeric = self.as_u8(); + let other_numeric = other.as_u8(); self_numeric < other_numeric } @@ -139,15 +131,8 @@ impl PartialOrd for PartInfo { } fn gt(&self, other: &Self) -> bool { - let self_numeric = match self { - Part(number) => number, - NoParts => &0, - }; - - let other_numeric = match other { - Part(number) => number, - NoParts => &0, - }; + let self_numeric = self.as_u8(); + let other_numeric = other.as_u8(); self_numeric > other_numeric } @@ -284,10 +269,7 @@ pub(crate) async fn check_feed(series_slug: &str, series_has_parts: bool) -> Res lemmy_info: post_details, }; - let part_id = match new_part_info { - Part(number) => number, - NoParts => 0, - }; + let part_id = new_part_info.as_u8(); if publishing_date <= Utc::now() { volume_map