wallhaven_rs/models/enums/
resolution.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5/// Resolutions you can filter by.
6///
7/// You can check out [`Resolution::dimensions`] for numerical values.
8///
9/// This cannot be customized further as only values allowed by wallhaven can be used.
10#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
11pub enum Resolution {
12    /// A resolution of 1280 by 720 pixels
13    #[serde(rename = "1280x720")]
14    R1280x720,
15    /// A resolution of 1280 by 800 pixels
16    #[serde(rename = "1280x800")]
17    R1280x800,
18    /// A resolution of 1280 by 960 pixels
19    #[serde(rename = "1280x960")]
20    R1280x960,
21    /// A resolution of 1280 by 1024 pixels
22    #[serde(rename = "1280x1024")]
23    R1280x1024,
24    /// A resolution of 3440 by 1440 pixels
25    #[serde(rename = "3440x1440")]
26    R3440x1440,
27    /// A resolution of 1600 by 900 pixels
28    #[serde(rename = "1600x900")]
29    R1600x900,
30    /// A resolution of 1600 by 1000 pixels
31    #[serde(rename = "1600x1000")]
32    R1600x1000,
33    /// A resolution of 1600 by 1200 pixels
34    #[serde(rename = "1600x1200")]
35    R1600x1200,
36    /// A resolution of 1600 by 1280 pixels
37    #[serde(rename = "1600x1280")]
38    R1600x1280,
39    /// A resolution of 3840 by 1600 pixels
40    #[serde(rename = "3840x1600")]
41    R3840x1600,
42    /// A resolution of 1920 by 1080 pixels
43    #[serde(rename = "1920x1080")]
44    R1920x1080,
45    /// A resolution of 1920 by 1200 pixels
46    #[serde(rename = "1920x1200")]
47    R1920x1200,
48    /// A resolution of 1920 by 1440 pixels
49    #[serde(rename = "1920x1440")]
50    R1920x1440,
51    /// A resolution of 1920 by 1536 pixels
52    #[serde(rename = "1920x1536")]
53    R1920x1536,
54    /// A resolution of 2560 by 1080 pixels
55    #[serde(rename = "2560x1080")]
56    R2560x1080,
57    /// A resolution of 2560 by 1440 pixels
58    #[serde(rename = "2560x1440")]
59    R2560x1440,
60    /// A resolution of 2560 by 1600 pixels
61    #[serde(rename = "2560x1600")]
62    R2560x1600,
63    /// A resolution of 2560 by 1920 pixels
64    #[serde(rename = "2560x1920")]
65    R2560x1920,
66    /// A resolution of 2560 by 2048 pixels
67    #[serde(rename = "2560x2048")]
68    R2560x2048,
69    /// A resolution of 3840 by 2160 pixels
70    #[serde(rename = "3840x2160")]
71    R3840x2160,
72    /// A resolution of 3840 by 2400 pixels
73    #[serde(rename = "3840x2400")]
74    R3840x2400,
75    /// A resolution of 3840 by 2880 pixels
76    #[serde(rename = "3840x2880")]
77    R3840x2880,
78    /// A resolution of 3840 by 3072 pixels
79    #[serde(rename = "3840x3072")]
80    R3840x3072,
81}
82
83impl Resolution {
84    /// A shorthand for a match case returning the actual width and height of the resolution
85    ///
86    /// Basically, for R(W)x(H) will return (W, H)
87    #[must_use]
88    pub const fn dimensions(&self) -> (u32, u32) {
89        match self {
90            Self::R1280x720 => (1280, 720),
91            Self::R1280x800 => (1280, 800),
92            Self::R1280x960 => (1280, 960),
93            Self::R1600x900 => (1600, 900),
94            Self::R1280x1024 => (1280, 1024),
95            Self::R3440x1440 => (3440, 1440),
96            Self::R1600x1000 => (1600, 1000),
97            Self::R1600x1200 => (1600, 1200),
98            Self::R1600x1280 => (1600, 1280),
99            Self::R3840x1600 => (3840, 1600),
100            Self::R1920x1080 => (1920, 1080),
101            Self::R1920x1200 => (1920, 1200),
102            Self::R1920x1440 => (1920, 1440),
103            Self::R1920x1536 => (1920, 1536),
104            Self::R2560x1080 => (2560, 1080),
105            Self::R2560x1440 => (2560, 1440),
106            Self::R2560x1600 => (2560, 1600),
107            Self::R2560x1920 => (2560, 1920),
108            Self::R2560x2048 => (2560, 2048),
109            Self::R3840x2160 => (3840, 2160),
110            Self::R3840x2400 => (3840, 2400),
111            Self::R3840x2880 => (3840, 2880),
112            Self::R3840x3072 => (3840, 3072),
113        }
114    }
115}
116
117impl Display for Resolution {
118    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
119        let (w, h) = self.dimensions();
120        write!(f, "{w}x{h}")
121    }
122}