use core::fmt;
use crate::TimecodeError;
const MALFORMED_MESSAGE: &str = "malformed MIDI Time Code message";
const INVALID_TIMECODE: &str = "MIDI Time Code carries an invalid timecode";
const NO_RATE_CODE: &str = "frame rate has no MIDI Time Code rate code";
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum MtcError {
MalformedMessage,
InvalidTimecode(TimecodeError),
NoRateCode,
}
impl fmt::Display for MtcError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::MalformedMessage => MALFORMED_MESSAGE,
Self::InvalidTimecode(_) => INVALID_TIMECODE,
Self::NoRateCode => NO_RATE_CODE,
})
}
}
impl core::error::Error for MtcError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::InvalidTimecode(error) => Some(error),
Self::MalformedMessage | Self::NoRateCode => None,
}
}
}