Skip to main content

talw_timecode/
error.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3use core::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum TimecodeError {
7    InvalidFormat,
8    InvalidHours(u8),
9    InvalidMinutes(u8),
10    InvalidSeconds(u8),
11    InvalidFrames(u8, u8),
12    InvalidDropFrameRate,
13    MismatchedRates,
14}
15
16impl fmt::Display for TimecodeError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::InvalidFormat => write!(f, "invalid timecode format"),
20            Self::InvalidHours(h) => write!(f, "hours {h} out of range 0-23"),
21            Self::InvalidMinutes(m) => write!(f, "minutes {m} out of range 0-59"),
22            Self::InvalidSeconds(s) => write!(f, "seconds {s} out of range 0-59"),
23            Self::InvalidFrames(fr, max) => {
24                write!(f, "frames {fr} out of range 0-{}", max - 1)
25            }
26            Self::InvalidDropFrameRate => {
27                write!(f, "drop-frame only valid for 29.97 and 59.94 fps")
28            }
29            Self::MismatchedRates => write!(f, "cannot operate on timecodes with different rates"),
30        }
31    }
32}
33
34#[cfg(feature = "std")]
35impl std::error::Error for TimecodeError {}