Skip to main content

alpha2_time/
error.rs

1use core::fmt;
2
3/// Invalid rational frame rate.
4#[derive(Copy, Clone, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum FrameRateError {
7    /// Zero numerator.
8    ZeroNumerator,
9    /// Zero denominator.
10    ZeroDenominator,
11    /// Frame duration is below one tick.
12    ExceedsTimelineResolution,
13}
14impl std::error::Error for FrameRateError {}
15impl fmt::Display for FrameRateError {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        f.write_str(match self {
18            Self::ZeroNumerator => "frame-rate numerator must not be zero",
19            Self::ZeroDenominator => "frame-rate denominator must not be zero",
20            Self::ExceedsTimelineResolution => "frame rate exceeds timeline resolution",
21        })
22    }
23}
24
25/// Invalid time range.
26#[derive(Copy, Clone, Debug, PartialEq, Eq)]
27#[non_exhaustive]
28pub enum TimeRangeError {
29    /// End precedes start.
30    EndBeforeStart,
31}
32impl std::error::Error for TimeRangeError {}
33impl fmt::Display for TimeRangeError {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        f.write_str("time-range end must not precede start")
36    }
37}