use std::{error::Error, fmt}; use super::task::TaskId; /// Task system's error type definition, representing when internal errors occurs. #[derive(Debug, thiserror::Error)] pub enum SystemError { #[error("task not found ")] TaskNotFound(TaskId), #[error("task aborted ")] TaskAborted(TaskId), #[error("task join error ")] TaskJoin(TaskId), #[error("forced abortion for task timed out")] TaskForcedAbortTimeout(TaskId), } /// Trait for errors that can be returned by tasks, we use this trait as a bound for the task system generic /// error type. /// ///With this trait, we can have a unified error type through all the tasks in the system. pub trait RunError: Error + fmt::Debug + Send + Sync + 'static {} /// We provide a blanket implementation for all types that also implements /// [`std::error::Error`](https://doc.rust-lang.org/std/error/trait.Error.html) and /// [`std::fmt::Debug`](https://doc.rust-lang.org/std/fmt/trait.Debug.html). /// So you will not need to implement this trait for your error type, just implement the `Error` and `Debug` impl RunError for T {}