Skip to main content

tmdb_rs/
image.rs

1const BASE: &str = "https://image.tmdb.org/t/p";
2
3macro_rules! paths {
4    ($($name:ident { $($method:ident = $key:literal),* $(,)? }),* $(,)?) => {$(
5        /// an image path; call a size method for the full url
6        #[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
7        #[serde(transparent)]
8        pub struct $name(String);
9
10        impl $name {
11            $(
12                pub fn $method(&self) -> String {
13                    format!("{BASE}/{}{}", $key, self.0)
14                }
15            )*
16
17            /// the full url at the original upload size
18            pub fn original(&self) -> String {
19                format!("{BASE}/original{}", self.0)
20            }
21
22            /// the raw `*_path` value, for storage
23            pub fn path(&self) -> &str {
24                &self.0
25            }
26        }
27    )*};
28}
29
30paths! {
31    Poster { w92 = "w92", w154 = "w154", w185 = "w185", w342 = "w342", w500 = "w500", w780 = "w780" },
32    Backdrop { w300 = "w300", w780 = "w780", w1280 = "w1280" },
33    Profile { w45 = "w45", w185 = "w185", h632 = "h632" },
34    Still { w92 = "w92", w185 = "w185", w300 = "w300" },
35    Logo { w45 = "w45", w92 = "w92", w154 = "w154", w185 = "w185", w300 = "w300", w500 = "w500" },
36}