smpte_timecode/timecode/
errors.rs1use core::fmt;
2
3const UNSUPPORTED_FRAME_RATE: &str = "unsupported frame rate";
4const INVALID_SYNTAX: &str = "timecode must be written as HH:MM:SS:FF";
5const DROP_FRAME_SEPARATOR: &str = "only a drop-frame rate takes a ';' frame separator";
6const FIELD_OUT_OF_RANGE: &str = "timecode field is out of range for the frame rate";
7const DROPPED_LABEL: &str = "drop-frame timecode skips this label";
8const FRAME_OUT_OF_RANGE: &str = "frame position is outside the 24-hour day";
9const ZERO_DENOMINATOR: &str = "ratio denominator is zero";
10const ZERO_SAMPLE_RATE: &str = "sample rate is zero";
11const OVERFLOW: &str = "arithmetic overflow";
12
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
15#[non_exhaustive]
16pub enum TimecodeError {
17 UnsupportedFrameRate,
20 InvalidSyntax,
22 DropFrameSeparator,
24 FieldOutOfRange,
26 DroppedLabel,
28 FrameOutOfRange,
30 ZeroDenominator,
32 ZeroSampleRate,
34 Overflow,
36}
37
38impl TimecodeError {
39 const fn message(self) -> &'static str {
40 match self {
41 Self::UnsupportedFrameRate => UNSUPPORTED_FRAME_RATE,
42 Self::InvalidSyntax => INVALID_SYNTAX,
43 Self::DropFrameSeparator => DROP_FRAME_SEPARATOR,
44 Self::FieldOutOfRange => FIELD_OUT_OF_RANGE,
45 Self::DroppedLabel => DROPPED_LABEL,
46 Self::FrameOutOfRange => FRAME_OUT_OF_RANGE,
47 Self::ZeroDenominator => ZERO_DENOMINATOR,
48 Self::ZeroSampleRate => ZERO_SAMPLE_RATE,
49 Self::Overflow => OVERFLOW,
50 }
51 }
52}
53
54impl fmt::Display for TimecodeError {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 f.write_str(self.message())
57 }
58}
59
60impl core::error::Error for TimecodeError {}