Skip to main content

twapi_v2/fields/
place_fields.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashSet;
3
4#[derive(Serialize, Deserialize, Debug, Eq, Hash, PartialEq, Clone)]
5#[derive(Default)]
6pub enum PlaceFields {
7    #[serde(rename = "contained_within")]
8    #[default]
9    ContainedWithin,
10    #[serde(rename = "country")]
11    Country,
12    #[serde(rename = "country_code")]
13    CountryCode,
14    #[serde(rename = "full_name")]
15    FullName,
16    #[serde(rename = "geo")]
17    Geo,
18    #[serde(rename = "id")]
19    Id,
20    #[serde(rename = "name")]
21    Name,
22    #[serde(rename = "place_type")]
23    PlaceType,
24}
25
26impl PlaceFields {
27    pub fn all() -> HashSet<Self> {
28        let mut result = HashSet::new();
29        result.insert(Self::ContainedWithin);
30        result.insert(Self::Country);
31        result.insert(Self::CountryCode);
32        result.insert(Self::FullName);
33        result.insert(Self::Geo);
34        result.insert(Self::Id);
35        result.insert(Self::Name);
36        result.insert(Self::PlaceType);
37        result
38    }
39}
40
41impl std::fmt::Display for PlaceFields {
42    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
43        match self {
44            Self::ContainedWithin => write!(f, "contained_within"),
45            Self::Country => write!(f, "country"),
46            Self::CountryCode => write!(f, "country_code"),
47            Self::FullName => write!(f, "full_name"),
48            Self::Geo => write!(f, "geo"),
49            Self::Id => write!(f, "id"),
50            Self::Name => write!(f, "name"),
51            Self::PlaceType => write!(f, "place_type"),
52        }
53    }
54}
55