multipool/
errors.rs

1//! Error types for the thread pool.
2//!
3//! This module defines errors that may occur during the operation of the thread pool.
4//! These errors include situations such as task submission to a shut-down pool or task execution failures.
5
6/// Represents errors that can occur in the thread pool.
7///
8/// This enum provides error types for common issues encountered while managing
9/// and executing tasks in the thread pool.
10#[allow(dead_code)]
11#[derive(Debug)]
12pub enum PoolError {
13    /// The thread pool has been shut down, and no new tasks can be accepted.
14    PoolShutdown,
15    /// A generic error indicating that a task panicked or failed to join.
16    JoinError,
17}
18
19impl std::fmt::Display for PoolError {
20    /// Formats the `PoolError` for display.
21    ///
22    /// # Arguments
23    /// - `f`: A mutable reference to the formatter.
24    ///
25    /// # Returns
26    /// A `Result` indicating whether the formatting was successful.
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            PoolError::PoolShutdown => write!(f, "Thread pool is shut down"),
30            PoolError::JoinError => write!(f, "Task panicked or failed to join"),
31        }
32    }
33}
34
35impl std::error::Error for PoolError {}