feat(errors): Using SerializeDisplay for better error management with Result

This commit is contained in:
quexeky
2025-01-19 17:17:51 +11:00
parent c2f54c1dbc
commit 170fde5e23
15 changed files with 74 additions and 107 deletions

View File

@ -0,0 +1,27 @@
use std::{fmt::Display, io, sync::mpsc::SendError};
use serde_with::SerializeDisplay;
#[derive(SerializeDisplay)]
pub enum InternalError<T> {
IOError(io::Error),
SignalError(SendError<T>)
}
impl<T> Display for InternalError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InternalError::IOError(error) => write!(f, "{}", error.to_string()),
InternalError::SignalError(send_error) => write!(f, "{}", send_error.to_string()),
}
}
}
impl<T> From<SendError<T>> for InternalError<T> {
fn from(value: SendError<T>) -> Self {
InternalError::SignalError(value)
}
}
impl<T> From<io::Error> for InternalError<T> {
fn from(value: io::Error) -> Self {
InternalError::IOError(value)
}
}

View File

@ -7,3 +7,4 @@ pub mod downloadable_metadata;
pub mod progress_object;
pub mod queue;
pub mod rolling_progress_updates;
pub mod internal_error;