From 7127dd57c6b6015d754dd848c3ff2cd9df0d145e Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Tue, 11 Feb 2025 00:20:29 +0100 Subject: [PATCH] Derive defaults for sorting enums, remove ordering from films SQL query --- src/data_manager.rs | 9 +++++++-- src/ui/collatable_container/mod.rs | 29 +++++++++++------------------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/data_manager.rs b/src/data_manager.rs index 619461c..bb7037b 100644 --- a/src/data_manager.rs +++ b/src/data_manager.rs @@ -30,7 +30,6 @@ impl DataManager { . prepare ( " select uuid , name , original_name , release_date , runtime_minutes , poster_file_path from films - order by release_date desc " ) ? . query (()) ? . map (row_to_film_overview) @@ -126,7 +125,13 @@ fn row_to_series_overview ( row : & Row ) -> rusqlite :: Result . map ( PathBuf :: from ) ; let first_release_date = row . get (4) ? ; - Ok ( SeriesOverview { uuid , name , original_name , first_release_date , poster_file_path } ) + Ok ( SeriesOverview { + uuid , + name , + original_name , + first_release_date , + poster_file_path , + } ) } impl From for ZoodexError { diff --git a/src/ui/collatable_container/mod.rs b/src/ui/collatable_container/mod.rs index cf7b36d..6d306ac 100644 --- a/src/ui/collatable_container/mod.rs +++ b/src/ui/collatable_container/mod.rs @@ -24,15 +24,21 @@ pub trait MediaSorting < P : MediaProperty > : Clone + Copy + Debug + Default { pub trait MediaProperty : Clone + Copy + Debug + PartialEq {} -# [ derive ( Clone , Copy , Debug , PartialEq ) ] pub enum FilmProperty { Name , ReleaseDate , Runtime } -# [ derive ( Clone , Copy , Debug , PartialEq ) ] pub enum SeriesProperty { Name , FirstReleaseDate } -# [ derive ( Clone , Copy , Debug , PartialEq ) ] pub enum SortingDirection { Ascending , Descending } +# [ derive ( Clone , Copy , Debug , Default , PartialEq ) ] pub enum FilmProperty { + # [default] Name , ReleaseDate , Runtime , +} +# [ derive ( Clone , Copy , Debug , Default , PartialEq ) ] pub enum SeriesProperty { + # [default] Name , FirstReleaseDate , +} +# [ derive ( Clone , Copy , Debug , Default , PartialEq ) ] pub enum SortingDirection { + # [default] Ascending , Descending , +} -# [ derive ( Clone , Copy , Debug ) ] pub struct FilmsSorting { +# [ derive ( Clone , Copy , Debug , Default ) ] pub struct FilmsSorting { property : FilmProperty , direction : SortingDirection , } -# [ derive ( Clone , Copy , Debug ) ] pub struct SeriesSorting { +# [ derive ( Clone , Copy , Debug , Default ) ] pub struct SeriesSorting { property : SeriesProperty , direction : SortingDirection , } @@ -52,19 +58,6 @@ impl MediaSorting for SeriesSorting { fn get_direction ( & self ) -> SortingDirection { self . direction } } -impl Default for FilmsSorting { - fn default () -> Self { Self { - property : FilmProperty :: Name , - direction : SortingDirection :: Ascending , - } } -} -impl Default for SeriesSorting { - fn default () -> Self { Self { - property : SeriesProperty :: Name , - direction : SortingDirection :: Ascending , - } } -} - impl MediaProperty for FilmProperty {} impl MediaProperty for SeriesProperty {}