Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: relocate component trait #22

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading