dinio_sdk/models/geo.rs
1use serde::{Deserialize, Serialize};
2
3/// The regions, sub-regions and countries a geo ban can name (ISO 3166-1 + UN M49), as
4/// Core serves them from Relay's country table (`GET /api/v1/geo`). A geo ban `code` is
5/// valid only if it is in here at its level.
6///
7/// Read it with [`Geo::catalog`](crate::api::Geo::catalog); name lookups are methods
8/// ([`GeoCatalog::parse_area`], [`GeoCatalog::name`], [`GeoCatalog::known_areas`]).
9/// Core lets clients cache it for a day; serializable, so a caller can keep a copy.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct GeoCatalog {
12 /// Continent-sized UN M49 regions (`Europe`, 150).
13 pub regions: Vec<GeoRegion>,
14 /// UN M49 sub-regions (`Southern Europe`, 39).
15 pub subregions: Vec<GeoSubregion>,
16 /// Countries and territories (`Croatia`, 191).
17 pub countries: Vec<GeoCountry>,
18}
19
20/// A UN M49 region.
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22pub struct GeoRegion {
23 /// UN M49 region code.
24 pub code: u16,
25 /// English name.
26 pub name: String,
27}
28
29/// A UN M49 sub-region.
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub struct GeoSubregion {
32 /// UN M49 sub-region code.
33 pub code: u16,
34 /// English name.
35 pub name: String,
36 /// The region it belongs to.
37 pub region_code: u16,
38}
39
40/// A country or territory.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42pub struct GeoCountry {
43 /// ISO 3166-1 numeric code.
44 pub code: u16,
45 /// ISO 3166-1 alpha-2 code (`HR`).
46 pub alpha2: String,
47 /// ISO 3166-1 alpha-3 code (`HRV`).
48 pub alpha3: String,
49 /// English name.
50 pub name: String,
51 /// Its region; `None` for a country without one (Antarctica), which a region or
52 /// sub-region ban then never covers.
53 #[serde(default)]
54 pub region_code: Option<u16>,
55 /// Its sub-region; `None` like `region_code`.
56 #[serde(default)]
57 pub subregion_code: Option<u16>,
58}