use std::fmt;
use crate::lcw::LcwError;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
Parse,
Lcw(LcwError),
TooLarge(&'static str),
Video(&'static str),
UnsupportedSound(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Parse => write!(f, "malformed chunk structure"),
Error::Lcw(e) => write!(f, "malformed LCW data: {}", e),
Error::TooLarge(what) => write!(f, "{} exceeds sanity limits", what),
Error::Video(what) => write!(f, "malformed video data: {}", what),
Error::UnsupportedSound(what) => write!(f, "unsupported sound format: {}", what),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Lcw(e) => Some(e),
_ => None,
}
}
}
impl From<LcwError> for Error {
fn from(e: LcwError) -> Self {
Error::Lcw(e)
}
}