Refactoring pmoflac - factorisation des erreurs

This commit is contained in:
2025-10-27 22:47:59 +01:00
parent 28381bf19e
commit 56366ec678
6 changed files with 73 additions and 139 deletions

View File

@@ -12,6 +12,41 @@ use tokio::{
task::JoinHandle,
};
/// Generic error type shared by the streaming decoders.
#[derive(thiserror::Error, Debug, Clone)]
pub enum DecoderError {
#[error("I/O error ({kind:?}): {message}")]
Io {
kind: io::ErrorKind,
message: String,
},
#[error("{0}")]
Decode(String),
#[error("internal channel closed unexpectedly")]
ChannelClosed,
}
impl From<io::Error> for DecoderError {
fn from(err: io::Error) -> Self {
DecoderError::Io {
kind: err.kind(),
message: err.to_string(),
}
}
}
impl From<String> for DecoderError {
fn from(value: String) -> Self {
DecoderError::Decode(value)
}
}
impl From<&str> for DecoderError {
fn from(value: &str) -> Self {
DecoderError::Decode(value.to_owned())
}
}
/// Size of chunks when reading input data.
///
/// This size balances between efficient I/O operations and memory usage.