diff --git a/src/rust/core/kinds.rs b/src/rust/core/kinds.rs new file mode 100644 index 0000000..4bc5618 --- /dev/null +++ b/src/rust/core/kinds.rs @@ -0,0 +1,83 @@ +use std::{error::Error, fmt::Display}; + +#[derive(Debug, Clone)] +pub enum PresKind { + Html, + Pdf, + Generic, +} + +#[derive(Debug, Clone)] +pub enum ServiceItemKind { + Song, + Video, + Image, + Presentation(PresKind), + Content, +} + +impl std::fmt::Display for ServiceItemKind { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let s = match self { + Self::Song => "song".to_owned(), + Self::Image => "image".to_owned(), + Self::Video => "video".to_owned(), + Self::Presentation(PresKind::Html) => "html".to_owned(), + Self::Presentation(PresKind::Pdf) => "pdf".to_owned(), + Self::Presentation(PresKind::Generic) => { + "presentation".to_owned() + } + Self::Content => "content".to_owned(), + }; + write!(f, "{s}") + } +} + +impl TryFrom for ServiceItemKind { + type Error = ParseError; + fn try_from(value: String) -> Result { + match value.as_str() { + "song" => Ok(Self::Song), + "image" => Ok(Self::Image), + "video" => Ok(Self::Video), + "presentation" => { + Ok(Self::Presentation(PresKind::Generic)) + } + "html" => Ok(Self::Presentation(PresKind::Html)), + "pdf" => Ok(Self::Presentation(PresKind::Pdf)), + "content" => Ok(Self::Content), + _ => Err(ParseError::UnknownType), + } + } +} + +impl From for String { + fn from(val: ServiceItemKind) -> String { + match val { + ServiceItemKind::Song => "song".to_owned(), + ServiceItemKind::Video => "video".to_owned(), + ServiceItemKind::Image => "image".to_owned(), + ServiceItemKind::Presentation(_) => "presentation".to_owned(), + ServiceItemKind::Content => "content".to_owned(), + } + } +} + +#[derive(Debug)] +pub enum ParseError { + UnknownType, +} + +impl Error for ParseError {} + +impl Display for ParseError { + fn fmt( + &self, + f: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + let message = match self { + Self::UnknownType => "The type does not exist. It needs to be one of 'song', 'video', 'image', 'presentation', or 'content'", + }; + write!(f, "Error: {message}") + } +} diff --git a/src/rust/core/mod.rs b/src/rust/core/mod.rs new file mode 100644 index 0000000..ac8605d --- /dev/null +++ b/src/rust/core/mod.rs @@ -0,0 +1,2 @@ +pub mod service_items; +pub mod kinds; diff --git a/src/rust/core/service_items.rs b/src/rust/core/service_items.rs new file mode 100644 index 0000000..6276dd4 --- /dev/null +++ b/src/rust/core/service_items.rs @@ -0,0 +1,11 @@ +use super::kinds::ServiceItemKind; + +struct ServiceItem { + id: i32, + database_id: i32, + kind: ServiceItemKind, +} + +struct ServiceItemModel { + items: Vec, +} diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 10da268..8731099 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -13,4 +13,5 @@ pub mod utils; pub mod video_model; pub mod ytdl; pub mod slide_types; +pub mod core; // mod video_thumbnail;