tmdb_api/common/
mod.rs

1use std::borrow::Cow;
2
3pub mod country;
4pub mod credits;
5pub mod image;
6pub mod keyword;
7pub mod language;
8pub mod release_date;
9pub mod status;
10pub mod video;
11
12#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
13pub struct PaginatedResult<T> {
14    pub page: u64,
15    pub total_results: u64,
16    pub total_pages: u64,
17    pub results: Vec<T>,
18}
19
20#[derive(Clone, Debug, Deserialize, Serialize)]
21pub struct EntityResults<V> {
22    pub id: u64,
23    pub results: V,
24}
25
26#[derive(Clone, Debug, Deserialize, Serialize)]
27pub struct Results<V> {
28    pub results: V,
29}
30
31#[derive(Clone, Debug, Default, Serialize)]
32pub struct LanguageParams<'a> {
33    /// ISO 639-1 value to display translated data for the fields that support it.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub language: Option<Cow<'a, str>>,
36}
37
38impl<'a> LanguageParams<'a> {
39    pub fn set_language(&mut self, value: impl Into<Cow<'a, str>>) {
40        self.language = Some(value.into());
41    }
42
43    pub fn with_language(mut self, value: impl Into<Cow<'a, str>>) -> Self {
44        self.set_language(value);
45        self
46    }
47}
48
49#[derive(Clone, Debug, Default, serde::Serialize)]
50pub struct LanguagePageParams<'a> {
51    /// ISO 639-1 value to display translated data for the fields that support it.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub language: Option<Cow<'a, str>>,
54    /// Specify which page to query.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub page: Option<u32>,
57}
58
59impl<'a> LanguagePageParams<'a> {
60    pub fn set_language(&mut self, value: impl Into<Cow<'a, str>>) {
61        self.language = Some(value.into());
62    }
63
64    pub fn with_language(mut self, value: impl Into<Cow<'a, str>>) -> Self {
65        self.set_language(value);
66        self
67    }
68
69    pub fn set_page(&mut self, value: u32) {
70        self.page = Some(value);
71    }
72
73    pub fn with_page(mut self, value: u32) -> Self {
74        self.set_page(value);
75        self
76    }
77}