use std::{ io::ErrorKind, sync::{PoisonError, RwLockReadGuard, RwLockWriteGuard}, }; use crate::error::{AssembleError, IoError, IoErrorKind}; use super::{AssembleErrorKind, ThreadingError}; impl From for IoError { fn from(err: std::io::Error) -> Self { let kind = match err.kind() { ErrorKind::NotFound => IoErrorKind::NotFound, ErrorKind::PermissionDenied => IoErrorKind::PermissionDenied, ErrorKind::InvalidData => IoErrorKind::InvalidData, _ => IoErrorKind::Other, }; let msg = err.to_string(); Self::new(kind, Some(msg)) } } impl From for AssembleError { fn from(err: std::io::Error) -> Self { Self::new_other_error(AssembleErrorKind::Io(err.into())) } } // TODO: Maybe attempt recovery? To be honest we don't want any threads to panic at all, // or we want them all to panic spectacularly. impl From>> for AssembleError { fn from(err: PoisonError>) -> Self { Self::new_other_error(AssembleErrorKind::Threading(err.into())) } } impl From>> for ThreadingError { fn from(_err: PoisonError>) -> Self { Self::LockFailed } } impl From>> for AssembleError { fn from(err: PoisonError>) -> Self { Self::new_other_error(AssembleErrorKind::Threading(err.into())) } } impl From>> for ThreadingError { fn from(_err: PoisonError>) -> Self { Self::LockFailed } } impl From for AssembleError { fn from(err: std::fmt::Error) -> Self { IoError::new(IoErrorKind::Other, Some(err.to_string())).into() } } impl From for AssembleError { fn from(err: IoError) -> Self { Self::new_other_error(AssembleErrorKind::Io(err)) } }