From 7cc616e965b4a4eb5a8c759c7230f9d8d01821c0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 14 Jun 2023 20:38:19 +0200 Subject: generalize share props between item and dir --- common/src/lib.rs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'common/src') diff --git a/common/src/lib.rs b/common/src/lib.rs index 47015ff..c678cdb 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,13 +3,21 @@ pub mod r#impl; use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, path::PathBuf}; +use std::{collections::BTreeMap, path::PathBuf, ops::Deref}; #[derive(Debug, Clone, Deserialize, Serialize)] -pub struct DirectoryInfo { - pub name: String, - pub banner: Option, +pub struct CommmonInfo { + pub title: String, + #[serde(default)] pub tagline: Option, + #[serde(default)] pub description: Option, + #[serde(default)] pub poster: Option, + #[serde(default)] pub backdrop: Option, +} +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct DirectoryInfo { + #[serde(flatten)] + pub commmon: CommmonInfo, #[serde(default)] pub kind: DirectoryKind, } @@ -30,12 +38,9 @@ impl Default for DirectoryKind { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct ItemInfo { - pub title: String, + #[serde(flatten)] + pub commmon: CommmonInfo, pub duration: f64, // in seconds - pub description_head: String, - pub description: String, - pub poster: Option, - pub backdrop: Option, pub tracks: BTreeMap, } @@ -78,3 +83,16 @@ pub struct BlockIndex { pub source_off: usize, pub size: usize, } + +impl Deref for ItemInfo { + type Target = CommmonInfo; + fn deref(&self) -> &Self::Target { + &self.commmon + } +} +impl Deref for DirectoryInfo { + type Target = CommmonInfo; + fn deref(&self) -> &Self::Target { + &self.commmon + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2