1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
use std::future::Future; pub trait Routine: Send + Sync + 'static { /// Error type of a routine. Can be any type that implements the [Error](std::error::Error) trait, and can also be individual /// for different routines /// /// For a usage example check [Routine::run()](Routine::run) method type Err: Into<anyhow::Error> + Send + Sync + 'static; /// The method that [Manager](crate::manager::Manager) will call when calling [Manager::run()](Manager::run) /// /// **Example:** /// ``` /// use peachy::prelude::*; /// use thiserror::Error; /// /// #[tokio::main] /// async fn main() -> anyhow::Result<()> { /// Manager::new() /// .add_routine(RoutineA) /// .add_routine(RoutineB) /// .run() /// .await /// } /// /// pub struct RoutineA; /// /// impl Routine for RoutineA { /// type Err = RoutineAError; /// /// async fn run(self) -> Result<(), Self::Err> { Ok(()) } /// } /// /// pub struct RoutineB; /// /// impl Routine for RoutineB { /// type Err = RoutineBError; /// /// async fn run(self) -> Result<(), Self::Err> { Ok(()) } /// } /// /// #[derive(Error)] /// pub enum RoutineAError {} /// /// #[derive(Error)] /// pub enum RoutineBError {} /// ``` fn run(self) -> impl Future<Output = Result<(), Self::Err>> + Send + Sync + 'static; }