use std::{fmt, io};
#[derive(Debug)]
pub struct ThreadStartError {
thread: &'static str,
source: io::Error,
}
impl ThreadStartError {
#[must_use]
pub fn new(thread: &'static str, source: io::Error) -> Self {
Self { thread, source }
}
#[must_use]
pub fn thread(&self) -> &'static str {
self.thread
}
}
impl fmt::Display for ThreadStartError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "could not start the {} thread", self.thread)
}
}
impl std::error::Error for ThreadStartError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.source)
}
}
impl From<ThreadStartError> for io::Error {
fn from(error: ThreadStartError) -> Self {
let kind = error.source.kind();
Self::new(kind, error)
}
}