Skip to main content

crispy_iptv_types/
resolution.rs

1//! Stream resolution classification.
2
3use serde::{Deserialize, Serialize};
4
5/// Video resolution tier.
6#[derive(
7    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
8)]
9pub enum Resolution {
10    /// Unknown or undetectable resolution.
11    #[default]
12    Unknown,
13    /// Standard definition (≤576p).
14    SD,
15    /// High definition (720p).
16    HD,
17    /// Full high definition (1080p).
18    FHD,
19    /// Ultra high definition (2160p / 4K).
20    UHD,
21}
22
23impl std::fmt::Display for Resolution {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            Self::Unknown => write!(f, "Unknown"),
27            Self::SD => write!(f, "SD"),
28            Self::HD => write!(f, "HD"),
29            Self::FHD => write!(f, "FHD"),
30            Self::UHD => write!(f, "UHD"),
31        }
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn ordering_is_ascending() {
41        assert!(Resolution::SD < Resolution::HD);
42        assert!(Resolution::HD < Resolution::FHD);
43        assert!(Resolution::FHD < Resolution::UHD);
44    }
45
46    #[test]
47    fn default_is_unknown() {
48        assert_eq!(Resolution::default(), Resolution::Unknown);
49    }
50
51    #[test]
52    fn display_formats() {
53        assert_eq!(Resolution::UHD.to_string(), "UHD");
54        assert_eq!(Resolution::SD.to_string(), "SD");
55    }
56}