diff options
author | metamuffin <metamuffin@disroot.org> | 2023-06-14 20:44:36 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-06-14 20:44:36 +0200 |
commit | 16202a62e64a615d488f5bc376466029c31b00ad (patch) | |
tree | 10f8909f909c7115af4854a3c312ba3b91f37a4b /common | |
parent | 7cc616e965b4a4eb5a8c759c7230f9d8d01821c0 (diff) | |
download | jellything-16202a62e64a615d488f5bc376466029c31b00ad.tar jellything-16202a62e64a615d488f5bc376466029c31b00ad.tar.bz2 jellything-16202a62e64a615d488f5bc376466029c31b00ad.tar.zst |
refactor for last commit
Diffstat (limited to 'common')
-rw-r--r-- | common/src/lib.rs | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index c678cdb..2e80744 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,26 +3,44 @@ pub mod r#impl; use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, path::PathBuf, ops::Deref}; +use std::{ + collections::BTreeMap, + ops::{Deref, DerefMut}, + path::PathBuf, +}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct CommmonInfo { pub title: String, - #[serde(default)] pub tagline: Option<String>, - #[serde(default)] pub description: Option<String>, - #[serde(default)] pub poster: Option<PathBuf>, - #[serde(default)] pub backdrop: Option<PathBuf>, + #[serde(default)] + pub tagline: Option<String>, + #[serde(default)] + pub description: Option<String>, + #[serde(default)] + pub poster: Option<PathBuf>, + #[serde(default)] + pub backdrop: Option<PathBuf>, } #[derive(Debug, Clone, Deserialize, Serialize)] pub struct DirectoryInfo { #[serde(flatten)] - pub commmon: CommmonInfo, + pub common: CommmonInfo, #[serde(default)] pub kind: DirectoryKind, } #[derive(Debug, Clone, Deserialize, Serialize)] +pub struct ItemInfo { + #[serde(flatten)] + pub common: CommmonInfo, + pub duration: f64, // in seconds + pub tracks: BTreeMap<usize, SourceTrack>, +} + + + +#[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum DirectoryKind { Folder, @@ -37,14 +55,6 @@ impl Default for DirectoryKind { } #[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ItemInfo { - #[serde(flatten)] - pub commmon: CommmonInfo, - pub duration: f64, // in seconds - pub tracks: BTreeMap<usize, SourceTrack>, -} - -#[derive(Debug, Clone, Deserialize, Serialize)] pub struct SourceTrack { pub path: PathBuf, pub track_number: u64, @@ -87,12 +97,22 @@ pub struct BlockIndex { impl Deref for ItemInfo { type Target = CommmonInfo; fn deref(&self) -> &Self::Target { - &self.commmon + &self.common } } impl Deref for DirectoryInfo { type Target = CommmonInfo; fn deref(&self) -> &Self::Target { - &self.commmon + &self.common + } +} +impl DerefMut for ItemInfo { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.common } -}
\ No newline at end of file +} +impl DerefMut for DirectoryInfo { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.common + } +} |