smpte_timecode/mtc/
errors.rs1use core::fmt;
2
3use crate::TimecodeError;
4
5const MALFORMED_MESSAGE: &str = "malformed MIDI Time Code message";
6const INVALID_TIMECODE: &str = "MIDI Time Code carries an invalid timecode";
7const NO_RATE_CODE: &str = "frame rate has no MIDI Time Code rate code";
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
11#[non_exhaustive]
12pub enum MtcError {
13 MalformedMessage,
16 InvalidTimecode(TimecodeError),
19 NoRateCode,
22}
23
24impl fmt::Display for MtcError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 f.write_str(match self {
27 Self::MalformedMessage => MALFORMED_MESSAGE,
28 Self::InvalidTimecode(_) => INVALID_TIMECODE,
29 Self::NoRateCode => NO_RATE_CODE,
30 })
31 }
32}
33
34impl core::error::Error for MtcError {
35 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
36 match self {
37 Self::InvalidTimecode(error) => Some(error),
38 Self::MalformedMessage | Self::NoRateCode => None,
39 }
40 }
41}