From e8db0e98d52a3de37e8759c61c1feb8f0088e0fb Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 14 Sep 2024 22:57:48 +0200 Subject: [PATCH] Don't be verbose if not needed --- src/tui/app/machine/input.rs | 7 ++- src/tui/app/mod.rs | 86 ++++++++---------------------------- 2 files changed, 22 insertions(+), 71 deletions(-) diff --git a/src/tui/app/machine/input.rs b/src/tui/app/machine/input.rs index 5cd5a86..169bf58 100644 --- a/src/tui/app/machine/input.rs +++ b/src/tui/app/machine/input.rs @@ -29,10 +29,9 @@ impl IAppInput for AppInputMode { } fn cancel(mut self) -> Self::APP { - match &mut self.app { - AppState::Match(state) => state.submit_input(self.input), - _ => {} - } + if let AppState::Match(state) = &mut self.app { + state.submit_input(self.input) + }; self.app } } diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs index 2cefc08..deb5e6c 100644 --- a/src/tui/app/mod.rs +++ b/src/tui/app/mod.rs @@ -8,24 +8,15 @@ use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta, Collection}; use crate::tui::lib::interface::musicbrainz::Match; -pub enum AppState< - BrowseState, - InfoState, - ReloadState, - SearchState, - FetchState, - MatchState, - ErrorState, - CriticalState, -> { - Browse(BrowseState), - Info(InfoState), - Reload(ReloadState), - Search(SearchState), - Fetch(FetchState), - Match(MatchState), - Error(ErrorState), - Critical(CriticalState), +pub enum AppState { + Browse(B), + Info(I), + Reload(R), + Search(S), + Fetch(F), + Match(M), + Error(E), + Critical(C), } pub enum AppMode { @@ -33,6 +24,13 @@ pub enum AppMode { Input(InputMode), } +macro_rules! IAppState { + () => { + AppState + }; +} + pub trait IApp { type BrowseState: IAppBase + IAppInteractBrowse; type InfoState: IAppBase + IAppInteractInfo; @@ -49,36 +47,10 @@ pub trait IApp { fn is_running(&self) -> bool; fn force_quit(self) -> Self; - #[allow(clippy::type_complexity)] - fn state( - self, - ) -> AppState< - Self::BrowseState, - Self::InfoState, - Self::ReloadState, - Self::SearchState, - Self::FetchState, - Self::MatchState, - Self::ErrorState, - Self::CriticalState, - >; + fn state(self) -> IAppState!(); #[allow(clippy::type_complexity)] - fn mode( - self, - ) -> AppMode< - AppState< - Self::BrowseState, - Self::InfoState, - Self::ReloadState, - Self::SearchState, - Self::FetchState, - Self::MatchState, - Self::ErrorState, - Self::CriticalState, - >, - Self::InputMode, - >; + fn mode(self) -> AppMode; } pub trait IAppBase { @@ -239,27 +211,7 @@ pub struct MatchStatePublic<'app> { pub type AppPublicState<'app> = AppState<(), (), (), &'app str, (), MatchStatePublic<'app>, &'app str, &'app str>; -impl< - BrowseState, - InfoState, - ReloadState, - SearchState, - FetchState, - MatchState, - ErrorState, - CriticalState, - > - AppState< - BrowseState, - InfoState, - ReloadState, - SearchState, - FetchState, - MatchState, - ErrorState, - CriticalState, - > -{ +impl AppState { pub fn is_search(&self) -> bool { matches!(self, AppState::Search(_)) }