Don't be verbose if not needed

This commit is contained in:
Wojciech Kozlowski 2024-09-14 22:57:48 +02:00
parent 20f36bcb0e
commit e8db0e98d5
2 changed files with 22 additions and 71 deletions

View File

@ -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
}
}

View File

@ -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<B, I, R, S, F, M, E, C> {
Browse(B),
Info(I),
Reload(R),
Search(S),
Fetch(F),
Match(M),
Error(E),
Critical(C),
}
pub enum AppMode<BrowseMode, InputMode> {
@ -33,6 +24,13 @@ pub enum AppMode<BrowseMode, InputMode> {
Input(InputMode),
}
macro_rules! IAppState {
() => {
AppState<Self::BrowseState, Self::InfoState, Self::ReloadState, Self::SearchState,
Self::FetchState, Self::MatchState, Self::ErrorState, Self::CriticalState>
};
}
pub trait IApp {
type BrowseState: IAppBase<APP = Self> + IAppInteractBrowse<APP = Self>;
type InfoState: IAppBase<APP = Self> + IAppInteractInfo<APP = Self>;
@ -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<IAppState!(), Self::InputMode>;
}
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<B, I, R, S, F, M, E, C> AppState<B, I, R, S, F, M, E, C> {
pub fn is_search(&self) -> bool {
matches!(self, AppState::Search(_))
}