Skip to content

Commit 029301b

Browse files
committed
Add Country deep geography types and drop Continent population_period.
1 parent 1528c2a commit 029301b

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ let place = parse.postal("28202", PostalOptions::default().country("US").deep(tr
123123
let property_tax = place.deep.as_ref().and_then(|deep| deep.property_tax.as_ref());
124124
```
125125

126-
Read `population_period` alongside `population`: a reporting year (`YYYY`) or period (`YYYY-YYYY`), null when unknown or unverifiable. Keep missing or null values unknown and preserve a known zero. These fields belong to full place profiles. State district lists include each district's population and period. Postal nearby and distance detail remains metropolitan associations only. Continent population and its period remain in core.
126+
Read `population_period` alongside `population`: a reporting year (`YYYY`) or period (`YYYY-YYYY`), null when unknown or unverifiable. Keep missing or null values unknown and preserve a known zero. These fields belong to full place profiles. State district lists include each district's population and period. Postal nearby and distance detail remains metropolitan associations only. Continent population stays in core.
127127

128128
Point returns the timezone ID with the core location. Its optional deep detail adds terrain and compact nearest-city context on every plan. A nearest city is null when none is within 200 km.
129129

‎src/types.rs‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ pub struct Continent {
4949
pub region: String,
5050
pub subregion: String,
5151
pub population: Option<i64>,
52-
/// Reporting year or period for population (YYYY or YYYY-YYYY). Null when unknown or unverifiable.
53-
pub population_period: Option<String>,
5452
pub area: Option<f64>,
5553
pub emoji: String,
5654
}
@@ -1448,6 +1446,16 @@ pub struct CountryDeep {
14481446
/// Reporting year or period for population (YYYY or YYYY-YYYY). Null when unknown or unverifiable.
14491447
pub population_period: Option<String>,
14501448
pub area: Option<f64>,
1449+
/// Land area in km2.
1450+
pub land_area: Option<f64>,
1451+
/// Water area in km2.
1452+
pub water_area: Option<f64>,
1453+
/// Coastline length in km. Zero is a known landlocked coastline.
1454+
pub coastline: Option<f64>,
1455+
/// Mean elevation in metres above sea level.
1456+
pub elevation: Option<f64>,
1457+
pub lowest_point: Option<CountryElevationPoint>,
1458+
pub highest_point: Option<CountryElevationPoint>,
14511459
pub tld: Option<String>,
14521460
pub borders: Option<Vec<String>>,
14531461
pub blocs: Option<Vec<String>>,
@@ -1473,6 +1481,14 @@ pub struct CountryDeep {
14731481
pub plate: Option<String>,
14741482
}
14751483

1484+
#[derive(Debug, Clone, Deserialize)]
1485+
#[non_exhaustive]
1486+
pub struct CountryElevationPoint {
1487+
pub name: Option<String>,
1488+
/// Elevation in metres above sea level. Values below sea level are negative.
1489+
pub elevation: f64,
1490+
}
1491+
14761492

14771493
#[derive(Debug, Clone, Default, Deserialize)]
14781494
#[serde(default)]

‎tests/country_geography.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use parseapi::Country;
2+
3+
#[test]
4+
fn country_geography_preserves_decimals_zero_and_negative_elevations() {
5+
let country: Country = serde_json::from_str(r#"{"country":"XX","deep":{"land_area":10010.5,"water_area":0,"coastline":0,"elevation":0,"lowest_point":{"name":null,"elevation":-430.5},"highest_point":{"name":"Summit","elevation":8848.86}}}"#).unwrap();
6+
let c = country.deep.unwrap();
7+
assert_eq!(c.land_area, Some(10010.5));
8+
assert_eq!(c.water_area, Some(0.0));
9+
assert_eq!(c.coastline, Some(0.0));
10+
assert_eq!(c.elevation, Some(0.0));
11+
let low = c.lowest_point.unwrap();
12+
assert_eq!(low.name, None);
13+
assert_eq!(low.elevation, -430.5);
14+
let high = c.highest_point.unwrap();
15+
assert_eq!(high.name.as_deref(), Some("Summit"));
16+
assert_eq!(high.elevation, 8848.86);
17+
}
18+
19+
#[test]
20+
fn older_locked_and_null_country_geography_remain_unknown() {
21+
for body in ["{}", r#"{"deep":{}}"#, r#"{"deep":{"land_area":null,"water_area":null,"coastline":null,"elevation":null,"lowest_point":null,"highest_point":null}}"#] {
22+
let country: Country = serde_json::from_str(body).unwrap();
23+
assert_eq!(country.deep.is_none(), body == "{}");
24+
if let Some(c) = country.deep {
25+
assert!(c.land_area.is_none() && c.water_area.is_none() && c.coastline.is_none() && c.elevation.is_none());
26+
assert!(c.lowest_point.is_none() && c.highest_point.is_none());
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)