From 2ad8625d8bdc7111e66a8566f1186a8fac670647 Mon Sep 17 00:00:00 2001 From: matsu Date: Fri, 5 Jan 2024 14:48:57 +0000 Subject: [PATCH] refactor: relocate component trait --- src/app.rs | 7 ------- src/app/components.rs | 7 +++++++ src/app/components/cmd_executor.rs | 3 +-- src/app/components/cmd_not_found.rs | 4 +--- src/app/components/wait.rs | 3 +-- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index 6a53942..f8a1240 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,13 +5,6 @@ mod supervise; pub use retry::*; pub use supervise::*; -#[async_trait::async_trait] -pub trait Component { - type Output; - - async fn handle(&self) -> Self::Output; -} - pub enum Transition { Next(N), Done(D), diff --git a/src/app/components.rs b/src/app/components.rs index 60dd8b8..60f6e4c 100644 --- a/src/app/components.rs +++ b/src/app/components.rs @@ -5,3 +5,10 @@ mod wait; pub use cmd_executor::*; pub use cmd_not_found::*; pub use wait::*; + +#[async_trait::async_trait] +pub trait Component { + type Output; + + async fn handle(&self) -> Self::Output; +} diff --git a/src/app/components/cmd_executor.rs b/src/app/components/cmd_executor.rs index 10d4b11..f45e488 100644 --- a/src/app/components/cmd_executor.rs +++ b/src/app/components/cmd_executor.rs @@ -1,4 +1,3 @@ -use crate::app::*; use crate::io::*; #[derive(new)] @@ -8,7 +7,7 @@ pub struct CmdExecutor { } #[async_trait::async_trait] -impl Component for CmdExecutor { +impl super::Component for CmdExecutor { type Output = anyhow::Result; async fn handle(&self) -> Self::Output { diff --git a/src/app/components/cmd_not_found.rs b/src/app/components/cmd_not_found.rs index 51ff2ff..9270f3a 100644 --- a/src/app/components/cmd_not_found.rs +++ b/src/app/components/cmd_not_found.rs @@ -1,5 +1,3 @@ -use crate::app::*; - #[derive(new)] pub struct PrintableCmdNotFound { pub command: String, @@ -7,7 +5,7 @@ pub struct PrintableCmdNotFound { } #[async_trait::async_trait] -impl> + Send + Sync> Component +impl> + Send + Sync> super::Component for PrintableCmdNotFound { type Output = anyhow::Result; diff --git a/src/app/components/wait.rs b/src/app/components/wait.rs index e683e37..fcb5c2c 100644 --- a/src/app/components/wait.rs +++ b/src/app/components/wait.rs @@ -1,4 +1,3 @@ -use crate::app::*; use crate::io::*; pub struct WaitSec { @@ -7,7 +6,7 @@ pub struct WaitSec { } #[async_trait::async_trait] -impl Component for WaitSec { +impl super::Component for WaitSec { type Output = (); async fn handle(&self) -> Self::Output {