Skip to content

Commit

Permalink
ref: Update countries lib (v5.7.1) (#29)
Browse files Browse the repository at this point in the history
* ref: update `countries` to v5.6.0
* ref: update `countries` lib to v5.7.1
* ref: check feature list length before declaring `#[cfg(...)]`
* feat: apply `distance_unit`
  • Loading branch information
pouriya authored Feb 12, 2024
1 parent 7ac3a91 commit a17943e
Show file tree
Hide file tree
Showing 269 changed files with 1,743 additions and 950 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ to = [] # The Kingdom of Tonga (Oceania)
tr = [] # The Republic of Türkiye (Asia)
tt = [] # The Republic of Trinidad and Tobago (Americas)
tv = [] # Tuvalu (Oceania)
tw = [] # The Republic of China (Asia)
tw = [] # Taiwan, Province of China (Asia)
tz = [] # The United Republic of Tanzania (Africa)
ua = [] # Ukraine (Europe)
ug = [] # The Republic of Uganda (Africa)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ assert_eq!(country.country_code(), 1);
assert_eq!(country.region(), Some(Region::Americas));
assert!(country.unofficial_name_list().contains(&"United States"));
assert!(country.spoken_language_list().contains(&"en"));
assert!(country.distance_unit().is_mi()); // KM/MI
assert!(country.g7_member() && country.g20_member());
assert!(!country.eu_member() && !country.eea_member()); // Not in `European Union` and `European Economic Area`
assert!(!country.gdpr_compliant()); // It's not GDPR compliant too!
Expand Down Expand Up @@ -62,9 +63,10 @@ assert_eq!(
* Phone number (E.164)
* GDPR compliance
* VAT (Value-added Tax) rate
* Distance unit
* ...
* Country Subdivisions. (Optional)
* GEO locations for countries and their subdivisions (Optional)
* Geolocations for countries and their subdivisions (Optional)
* Translations for countries and subdivisions (Optional)
* [`serde`](https://docs.rs/serde) integration (Optional)
* [`chrono`](https://docs.rs/chrono) integration (Optional)
Expand Down Expand Up @@ -254,7 +256,7 @@ let country = CountryIterator::new()
assert_eq!("Israel", country.iso_short_name());
```

### GEO
### Geo
Enable `geo` feature inside `Cargo.toml` file:
```toml
[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion countries
Submodule countries updated 272 files
26 changes: 16 additions & 10 deletions keshvar-code-generator/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,22 @@ lazy_static! { pub static ref UNSUPPORTED_COUNTRIES_COUNT: usize = ALL_COUNTRIES
sorted_region_features.sort();
for region in sorted_region_features {
let feature_list = region_features.get(region).unwrap();
consts_rs_file.write_all(b" #[\n cfg(\n all(\n")?;
consts_rs_file.write_all(
feature_list
.iter()
.map(|x| format!(" feature = {:?}", x))
.collect::<Vec<_>>()
.join(",\n")
.as_bytes(),
)?;
consts_rs_file.write_all(b"\n \n) )\n ]\n")?;
// ...
// #[cfg(all())]
// Region::Antarctica,
// ...
if !feature_list.is_empty() {
consts_rs_file.write_all(b" #[\n cfg(\n all(\n")?;
consts_rs_file.write_all(
feature_list
.iter()
.map(|x| format!(" feature = {:?}", x))
.collect::<Vec<_>>()
.join(",\n")
.as_bytes(),
)?;
consts_rs_file.write_all(b"\n \n) )\n ]\n")?;
}
consts_rs_file
.write_all(format!(" Region::{},\n", utils::capitalize(region)).as_bytes())?;
}
Expand Down
11 changes: 9 additions & 2 deletions keshvar-code-generator/src/countries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn generate_country(destination_file: &PathBuf, info: &CountryInfo) -> Resul
file.write_all(b"pub mod consts {\n")?;
file.write_all(b" #[allow(unused_imports)]\n")?;
file.write_all(
b" use crate::{Alpha2, Alpha3, GEC, IOC, CurrencyCode, Continent, Region, SubRegion, WorldRegion, WeekDay};\n\n",
b" use crate::{Alpha2, Alpha3, DistanceUnit, GEC, IOC, CurrencyCode, Continent, Region, SubRegion, WorldRegion, WeekDay};\n\n",
)?;
for (name, _type, value) in [
(
Expand Down Expand Up @@ -224,6 +224,11 @@ pub fn generate_country(destination_file: &PathBuf, info: &CountryInfo) -> Resul
"bool",
info.eu_member.unwrap_or(false).to_string(),
),
(
"const DISTANCE_UNIT",
"DistanceUnit",
format!("DistanceUnit::{:?}", info.distance_unit),
),
] {
file.write_all(format!(" pub {}: {} = {};\n", name, _type, value).as_bytes())?;
}
Expand Down Expand Up @@ -400,7 +405,7 @@ pub fn generate_country(destination_file: &PathBuf, info: &CountryInfo) -> Resul
file.write_all(b"}\n")?;
file.write_all(b"#[allow(unused_imports)]\n")?;
file.write_all(
b"use crate::{Alpha2, Alpha3, GEC, IOC, Country, CurrencyCode, Continent, Region, SubRegion, WorldRegion, WeekDay, VatRates};\n",
b"use crate::{Alpha2, Alpha3, DistanceUnit, GEC, IOC, Country, CurrencyCode, Continent, Region, SubRegion, WorldRegion, WeekDay, VatRates};\n",
)?;
file.write_all(b"#[allow(unused_imports)]\n")?;
file.write_all(b"use std::collections::HashMap;\n")?;
Expand Down Expand Up @@ -450,6 +455,7 @@ pub fn new() -> Country {{
eu_member: {},
eea_member: {},
vat_rates: {},
distance_unit: {},
}}
}}
"#,
Expand Down Expand Up @@ -512,6 +518,7 @@ pub fn new() -> Country {{
} else {
"None".to_string()
},
format!("DistanceUnit::{:?}", info.distance_unit),
)
.as_bytes(),
)?;
Expand Down
8 changes: 8 additions & 0 deletions keshvar-code-generator/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ pub struct CountryInfo {
pub eea_member: Option<bool>,
pub eu_member: Option<bool>,
pub vat_rates: Option<VatRates>,
pub distance_unit: DistanceUnit,
}

#[derive(Clone, Debug, Copy, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum DistanceUnit {
Km,
Mi,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions src/alpha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ pub enum Alpha2 {
/// Tuvalu (Oceania)
TV,
#[cfg(feature = "tw")]
/// The Republic of China (Asia)
/// Taiwan, Province of China (Asia)
TW,
#[cfg(feature = "tz")]
/// The United Republic of Tanzania (Africa)
Expand Down Expand Up @@ -1538,7 +1538,7 @@ mod impls {
"TT" => Ok(Self::TT),
#[cfg(feature = "tv")] // Tuvalu (Oceania)
"TV" => Ok(Self::TV),
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
"TW" => Ok(Self::TW),
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
"TZ" => Ok(Self::TZ),
Expand Down Expand Up @@ -3063,7 +3063,7 @@ mod impls {
Alpha2::TT => crate::countries::tt::new(),
#[cfg(feature = "tv")] // Tuvalu (Oceania)
Alpha2::TV => crate::countries::tv::new(),
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
Alpha2::TW => crate::countries::tw::new(),
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
Alpha2::TZ => crate::countries::tz::new(),
Expand Down Expand Up @@ -3571,7 +3571,7 @@ mod impls {
Alpha2::TT => Alpha3::TTO,
#[cfg(feature = "tv")] // Tuvalu (Oceania)
Alpha2::TV => Alpha3::TUV,
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
Alpha2::TW => Alpha3::TWN,
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
Alpha2::TZ => Alpha3::TZA,
Expand Down
8 changes: 4 additions & 4 deletions src/alpha3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ pub enum Alpha3 {
/// Tuvalu (Oceania)
TUV,
#[cfg(feature = "tw")]
/// The Republic of China (Asia)
/// Taiwan, Province of China (Asia)
TWN,
#[cfg(feature = "tz")]
/// The United Republic of Tanzania (Africa)
Expand Down Expand Up @@ -1555,7 +1555,7 @@ mod impls {
"TTO" => Ok(Self::TTO),
#[cfg(feature = "tv")] // Tuvalu (Oceania)
"TUV" => Ok(Self::TUV),
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
"TWN" => Ok(Self::TWN),
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
"TZA" => Ok(Self::TZA),
Expand Down Expand Up @@ -2064,7 +2064,7 @@ mod impls {
Alpha3::TTO => "TTO",
#[cfg(feature = "tv")] // Tuvalu (Oceania)
Alpha3::TUV => "TUV",
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
Alpha3::TWN => "TWN",
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
Alpha3::TZA => "TZA",
Expand Down Expand Up @@ -2573,7 +2573,7 @@ mod impls {
Alpha3::TTO => Alpha2::TT,
#[cfg(feature = "tv")] // Tuvalu (Oceania)
Alpha3::TUV => Alpha2::TV,
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
Alpha3::TWN => Alpha2::TW,
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
Alpha3::TZA => Alpha2::TZ,
Expand Down
3 changes: 1 addition & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ pub const SUPPORTED_ALPHA2_LIST: &[Alpha2] = &[
Alpha2::TT,
#[cfg(feature = "tv")] // Tuvalu (Oceania)
Alpha2::TV,
#[cfg(feature = "tw")] // The Republic of China (Asia)
#[cfg(feature = "tw")] // Taiwan, Province of China (Asia)
Alpha2::TW,
#[cfg(feature = "tz")] // The United Republic of Tanzania (Africa)
Alpha2::TZ,
Expand Down Expand Up @@ -1509,7 +1509,6 @@ pub const SUPPORTED_REGION_LIST: &[Region] = &[
feature = "vi"
))]
Region::Americas,
#[cfg(all())]
Region::Antarctica,
#[cfg(all(
feature = "ae",
Expand Down
9 changes: 6 additions & 3 deletions src/countries/ad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
pub mod consts {
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, CurrencyCode, Region, SubRegion, WeekDay, WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, CurrencyCode, DistanceUnit, Region, SubRegion, WeekDay,
WorldRegion, GEC, IOC,
};

pub const ADDRESS_FORMAT: Option<&str> = None;
Expand Down Expand Up @@ -42,6 +43,7 @@ pub mod consts {
pub const G20_MEMBER: bool = false;
pub const EU_MEMBER: bool = false;
pub const EEA_MEMBER: bool = false;
pub const DISTANCE_UNIT: DistanceUnit = DistanceUnit::Km;
#[cfg(feature = "emojis")]
pub const EMOJI: &str = "🇦🇩";
#[cfg(feature = "translations")]
Expand Down Expand Up @@ -406,8 +408,8 @@ pub mod subdivisions {
}
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, Country, CurrencyCode, Region, SubRegion, VatRates, WeekDay,
WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, Country, CurrencyCode, DistanceUnit, Region, SubRegion, VatRates,
WeekDay, WorldRegion, GEC, IOC,
};
#[allow(unused_imports)]
use std::collections::HashMap;
Expand Down Expand Up @@ -589,5 +591,6 @@ pub fn new() -> Country {
eu_member: false,
eea_member: false,
vat_rates: None,
distance_unit: DistanceUnit::Km,
}
}
9 changes: 6 additions & 3 deletions src/countries/ae.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
pub mod consts {
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, CurrencyCode, Region, SubRegion, WeekDay, WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, CurrencyCode, DistanceUnit, Region, SubRegion, WeekDay,
WorldRegion, GEC, IOC,
};

pub const ADDRESS_FORMAT: Option<&str> =
Expand Down Expand Up @@ -51,6 +52,7 @@ pub mod consts {
pub const G20_MEMBER: bool = false;
pub const EU_MEMBER: bool = false;
pub const EEA_MEMBER: bool = false;
pub const DISTANCE_UNIT: DistanceUnit = DistanceUnit::Km;
#[cfg(feature = "emojis")]
pub const EMOJI: &str = "🇦🇪";
#[cfg(feature = "translations")]
Expand Down Expand Up @@ -878,8 +880,8 @@ pub mod subdivisions {
}
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, Country, CurrencyCode, Region, SubRegion, VatRates, WeekDay,
WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, Country, CurrencyCode, DistanceUnit, Region, SubRegion, VatRates,
WeekDay, WorldRegion, GEC, IOC,
};
#[allow(unused_imports)]
use std::collections::HashMap;
Expand Down Expand Up @@ -926,5 +928,6 @@ pub fn new() -> Country {
eu_member: false,
eea_member: false,
vat_rates: Some(VatRates{standard: 5.0, reduced: Vec::from([]), super_reduced: None, parking: None}),
distance_unit: DistanceUnit::Km,
}
}
9 changes: 6 additions & 3 deletions src/countries/af.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
pub mod consts {
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, CurrencyCode, Region, SubRegion, WeekDay, WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, CurrencyCode, DistanceUnit, Region, SubRegion, WeekDay,
WorldRegion, GEC, IOC,
};

pub const ADDRESS_FORMAT: Option<&str> = None;
Expand Down Expand Up @@ -42,6 +43,7 @@ pub mod consts {
pub const G20_MEMBER: bool = false;
pub const EU_MEMBER: bool = false;
pub const EEA_MEMBER: bool = false;
pub const DISTANCE_UNIT: DistanceUnit = DistanceUnit::Km;
#[cfg(feature = "emojis")]
pub const EMOJI: &str = "🇦🇫";
#[cfg(feature = "translations")]
Expand Down Expand Up @@ -760,8 +762,8 @@ pub mod subdivisions {
}
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, Country, CurrencyCode, Region, SubRegion, VatRates, WeekDay,
WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, Country, CurrencyCode, DistanceUnit, Region, SubRegion, VatRates,
WeekDay, WorldRegion, GEC, IOC,
};
#[allow(unused_imports)]
use std::collections::HashMap;
Expand Down Expand Up @@ -946,5 +948,6 @@ pub fn new() -> Country {
eu_member: false,
eea_member: false,
vat_rates: None,
distance_unit: DistanceUnit::Km,
}
}
9 changes: 6 additions & 3 deletions src/countries/ag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
pub mod consts {
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, CurrencyCode, Region, SubRegion, WeekDay, WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, CurrencyCode, DistanceUnit, Region, SubRegion, WeekDay,
WorldRegion, GEC, IOC,
};

pub const ADDRESS_FORMAT: Option<&str> = None;
Expand Down Expand Up @@ -49,6 +50,7 @@ pub mod consts {
pub const G20_MEMBER: bool = false;
pub const EU_MEMBER: bool = false;
pub const EEA_MEMBER: bool = false;
pub const DISTANCE_UNIT: DistanceUnit = DistanceUnit::Km;
#[cfg(feature = "emojis")]
pub const EMOJI: &str = "🇦🇬";
#[cfg(feature = "translations")]
Expand Down Expand Up @@ -371,8 +373,8 @@ pub mod subdivisions {
}
#[allow(unused_imports)]
use crate::{
Alpha2, Alpha3, Continent, Country, CurrencyCode, Region, SubRegion, VatRates, WeekDay,
WorldRegion, GEC, IOC,
Alpha2, Alpha3, Continent, Country, CurrencyCode, DistanceUnit, Region, SubRegion, VatRates,
WeekDay, WorldRegion, GEC, IOC,
};
#[allow(unused_imports)]
use std::collections::HashMap;
Expand Down Expand Up @@ -419,5 +421,6 @@ pub fn new() -> Country {
eu_member: false,
eea_member: false,
vat_rates: None,
distance_unit: DistanceUnit::Km,
}
}
Loading

0 comments on commit a17943e

Please sign in to comment.