From da9505cd61e162c1cf9617c8ec790b6c440609af Mon Sep 17 00:00:00 2001 From: Neshura Date: Sun, 17 Dec 2023 14:42:00 +0100 Subject: [PATCH] Utility functions for jnovel module --- src/jnovel/mod.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/jnovel/mod.rs b/src/jnovel/mod.rs index d4a399c..616042d 100644 --- a/src/jnovel/mod.rs +++ b/src/jnovel/mod.rs @@ -74,8 +74,8 @@ pub(crate) struct ChapterDetail { #[derive(Debug, Clone)] pub(crate) struct LemmyPostInfo { - title: String, - url: Url, + pub(crate) title: String, + pub(crate) url: Url, } #[derive(Debug, Copy, Clone)] @@ -102,6 +102,10 @@ impl PartInfo { NoParts => 0, } } + + pub(crate) fn as_string(&self) -> String { + self.as_u8().to_string() + } } impl PartialEq for PartInfo { @@ -148,6 +152,22 @@ pub(crate) enum PostInfo { Volume { part: PartInfo, lemmy_info: LemmyPostInfo }, } +impl PostInfo { + pub(crate) fn get_part_info(&self) -> PartInfo { + match self { + Chapter {part: part_info, ..} => *part_info, + Volume {part: part_info, ..} => *part_info + } + } + + pub(crate) fn get_lemmy_info(&self) -> LemmyPostInfo { + match self { + Chapter {lemmy_info: lemmy_info, ..} => lemmy_info.clone(), + Volume {lemmy_info: lemmy_info, ..} => lemmy_info.clone() + } + } +} + impl PartialEq for PostInfo { fn eq(&self, other: &Self) -> bool { let self_part = match self {