| 1 | use std::{error::Error, fmt}; |
| 2 | |
| 3 | /// An error returned when a task could not be executed because a thread pool |
| 4 | /// was full. |
| 5 | /// |
| 6 | /// Contains the original task that failed to be submitted. This allows you to |
| 7 | /// try the submission again later or take some other action. |
| 8 | pub struct PoolFullError<T>(pub(crate) T); |
| 9 | |
| 10 | impl<T> PoolFullError<T> { |
| 11 | /// Extracts the inner task that could not be executed. |
| 12 | pub fn into_inner(self) -> T { |
| 13 | self.0 |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl<T> Error for PoolFullError<T> {} |
| 18 | |
| 19 | impl<T> fmt::Debug for PoolFullError<T> { |
| 20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 21 | f.write_str("PoolFullError(..)") |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | impl<T> fmt::Display for PoolFullError<T> { |
| 26 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 27 | f.write_str("thread pool is full") |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /// An error returned when attempting to configure the common thread pool after |
| 32 | /// it has already been initialized. |
| 33 | pub struct CommonAlreadyInitializedError(()); |
| 34 | |
| 35 | impl CommonAlreadyInitializedError { |
| 36 | pub(crate) fn new() -> Self { |
| 37 | Self(()) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | impl Error for CommonAlreadyInitializedError {} |
| 42 | |
| 43 | impl fmt::Debug for CommonAlreadyInitializedError { |
| 44 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 45 | f.write_str("CommonAlreadyInitializedError") |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl fmt::Display for CommonAlreadyInitializedError { |
| 50 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 51 | f.write_str("common thread pool already initialized") |
| 52 | } |
| 53 | } |