Add Util function to PartInfo Enum for easier number extraction
All checks were successful
Run Tests on Code / run-tests (push) Successful in 0s

This commit is contained in:
Neshura 2023-12-16 13:28:38 +01:00
parent 30e5fcbf72
commit 6187fa1230
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -95,20 +95,19 @@ impl PartInfo {
pub(crate) fn is_no_parts(&self) -> bool { pub(crate) fn is_no_parts(&self) -> bool {
!self.is_parts() !self.is_parts()
} }
pub(crate) fn as_u8(&self) -> u8 {
match self {
Part(number) => *number,
NoParts => 0,
}
}
} }
impl PartialEq for PartInfo { impl PartialEq for PartInfo {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
let self_numeric = match self { let self_numeric = self.as_u8();
Part(number) => number, let other_numeric = other.as_u8();
NoParts => &0,
};
let other_numeric = match other {
Part(number) => number,
NoParts => &0,
};
self_numeric == other_numeric self_numeric == other_numeric
} }
} }
@ -121,15 +120,8 @@ impl PartialOrd for PartInfo {
} }
fn lt(&self, other: &Self) -> bool { fn lt(&self, other: &Self) -> bool {
let self_numeric = match self { let self_numeric = self.as_u8();
Part(number) => number, let other_numeric = other.as_u8();
NoParts => &0,
};
let other_numeric = match other {
Part(number) => number,
NoParts => &0,
};
self_numeric < other_numeric self_numeric < other_numeric
} }
@ -139,15 +131,8 @@ impl PartialOrd for PartInfo {
} }
fn gt(&self, other: &Self) -> bool { fn gt(&self, other: &Self) -> bool {
let self_numeric = match self { let self_numeric = self.as_u8();
Part(number) => number, let other_numeric = other.as_u8();
NoParts => &0,
};
let other_numeric = match other {
Part(number) => number,
NoParts => &0,
};
self_numeric > other_numeric 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, lemmy_info: post_details,
}; };
let part_id = match new_part_info { let part_id = new_part_info.as_u8();
Part(number) => number,
NoParts => 0,
};
if publishing_date <= Utc::now() { if publishing_date <= Utc::now() {
volume_map volume_map