Skip to content

Commit

Permalink
Merge pull request #22 from tmtmtoo:component
Browse files Browse the repository at this point in the history
refactor: relocate component trait
  • Loading branch information
tmtmtoo authored Jan 5, 2024
2 parents c4fdcac + 2ad8625 commit ad30c46
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
7 changes: 0 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, D> {
Next(N),
Done(D),
Expand Down
7 changes: 7 additions & 0 deletions src/app/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 1 addition & 2 deletions src/app/components/cmd_executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::app::*;
use crate::io::*;

#[derive(new)]
Expand All @@ -8,7 +7,7 @@ pub struct CmdExecutor {
}

#[async_trait::async_trait]
impl Component for CmdExecutor {
impl super::Component for CmdExecutor {
type Output = anyhow::Result<Exit>;

async fn handle(&self) -> Self::Output {
Expand Down
4 changes: 1 addition & 3 deletions src/app/components/cmd_not_found.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::app::*;

#[derive(new)]
pub struct PrintableCmdNotFound<C> {
pub command: String,
pub inner: C,
}

#[async_trait::async_trait]
impl<T: 'static, C: Component<Output = anyhow::Result<T>> + Send + Sync> Component
impl<T: 'static, C: super::Component<Output = anyhow::Result<T>> + Send + Sync> super::Component
for PrintableCmdNotFound<C>
{
type Output = anyhow::Result<T>;
Expand Down
3 changes: 1 addition & 2 deletions src/app/components/wait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::app::*;
use crate::io::*;

pub struct WaitSec {
Expand All @@ -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 {
Expand Down

0 comments on commit ad30c46

Please sign in to comment.