use std::sync::Arc; #[async_trait::async_trait] pub trait Task { async fn id(&self) -> anyhow::Result; async fn should_run(&self) -> anyhow::Result { Ok(true) } async fn execute(&self) -> anyhow::Result<()>; } pub trait IntoTask { fn into_task(self) -> ConcreteTask; } #[derive(Clone)] pub struct ConcreteTask { inner: Arc, } impl ConcreteTask { pub fn new(t: T) -> Self { Self { inner: Arc::new(t) } } } impl std::ops::Deref for ConcreteTask { type Target = Arc; fn deref(&self) -> &Self::Target { &self.inner } } impl IntoTask for ConcreteTask { fn into_task(self) -> ConcreteTask { self } } impl IntoTask for T { fn into_task(self) -> ConcreteTask { ConcreteTask::new(self) } }