Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add kosovo #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/alpha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub const ISO_A2_KEN: &str = "KE";
pub const ISO_A2_KIR: &str = "KI";
pub const ISO_A2_PRK: &str = "KP";
pub const ISO_A2_KOR: &str = "KR";
pub const ISO_A2_XKX: &str = "XK";
pub const ISO_A2_KWT: &str = "KW";
pub const ISO_A2_KGZ: &str = "KG";
pub const ISO_A2_LAO: &str = "LA";
Expand Down
1 change: 1 addition & 0 deletions src/alpha3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub const ISO_A3_KEN: &str = "KEN";
pub const ISO_A3_KIR: &str = "KIR";
pub const ISO_A3_PRK: &str = "PRK";
pub const ISO_A3_KOR: &str = "KOR";
pub const ISO_A3_XKX: &str = "XKX";
pub const ISO_A3_KWT: &str = "KWT";
pub const ISO_A3_KGZ: &str = "KGZ";
pub const ISO_A3_LAO: &str = "LAO";
Expand Down
2 changes: 1 addition & 1 deletion src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.


pub const ISO_FULL_AFG: &str = "Afghanistan";
pub const ISO_FULL_ALA: &str = "Åland Islands";
pub const ISO_FULL_ALB: &str = "Albania";
Expand Down Expand Up @@ -140,6 +139,7 @@ pub const ISO_FULL_KEN: &str = "Kenya";
pub const ISO_FULL_KIR: &str = "Kiribati";
pub const ISO_FULL_PRK: &str = "Korea (Democratic People's Republic of)";
pub const ISO_FULL_KOR: &str = "Korea (Republic of)";
pub const ISO_FULL_XKX: &str = "Kosovo";
pub const ISO_FULL_KWT: &str = "Kuwait";
pub const ISO_FULL_KGZ: &str = "Kyrgyzstan";
pub const ISO_FULL_LAO: &str = "Lao People's Democratic Republic";
Expand Down
42 changes: 27 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.


use std::fmt::{self, Display};
use serde::{Serialize, Serializer, Deserialize, Deserializer};
use serde::de::{self, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::{self, Display};
use thiserror::Error;

/// Two-character uppercase ISO 3166-1 strings for each country
Expand Down Expand Up @@ -278,6 +277,8 @@ pub enum CountryCode {
PRK,
/// Korea (Republic of)
KOR,
/// Kosovo
XKX,
/// Kuwait
KWT,
/// Kyrgyzstan
Expand Down Expand Up @@ -551,7 +552,7 @@ pub enum CountryCodeParseErr {
InvalidID { unknown: u32 },
}

const NUM_COUNTRY_CODES: usize = 249;
const NUM_COUNTRY_CODES: usize = 250;

impl CountryCode {
/// Returns the ISO 3166-1 English short name
Expand Down Expand Up @@ -678,6 +679,7 @@ impl CountryCode {
KIR => ISO_FULL_KIR,
PRK => ISO_FULL_PRK,
KOR => ISO_FULL_KOR,
XKX => ISO_FULL_XKX,
KWT => ISO_FULL_KWT,
KGZ => ISO_FULL_KGZ,
LAO => ISO_FULL_LAO,
Expand Down Expand Up @@ -935,6 +937,7 @@ impl CountryCode {
KIR => ISO_NUM_KIR,
PRK => ISO_NUM_PRK,
KOR => ISO_NUM_KOR,
XKX => ISO_NUM_XKX,
KWT => ISO_NUM_KWT,
KGZ => ISO_NUM_KGZ,
LAO => ISO_NUM_LAO,
Expand Down Expand Up @@ -1192,6 +1195,7 @@ impl CountryCode {
KIR => ISO_A2_KIR,
PRK => ISO_A2_PRK,
KOR => ISO_A2_KOR,
XKX => ISO_A2_XKX,
KWT => ISO_A2_KWT,
KGZ => ISO_A2_KGZ,
LAO => ISO_A2_LAO,
Expand Down Expand Up @@ -1449,6 +1453,7 @@ impl CountryCode {
KIR => ISO_A3_KIR,
PRK => ISO_A3_PRK,
KOR => ISO_A3_KOR,
XKX => ISO_A3_XKX,
KWT => ISO_A3_KWT,
KGZ => ISO_A3_KGZ,
LAO => ISO_A3_LAO,
Expand Down Expand Up @@ -1585,8 +1590,8 @@ impl CountryCode {
/// Attempts to determine the ISO 3166-1 CountryCode for the given two-character string,
/// assuming it is in upper-case characters
pub fn for_alpha2(value: &str) -> Result<CountryCode, CountryCodeParseErr> {
use CountryCode::*;
use alpha2::*;
use CountryCode::*;
match value {
ISO_A2_AFG => Ok(AFG),
ISO_A2_ALA => Ok(ALA),
Expand Down Expand Up @@ -1707,6 +1712,7 @@ impl CountryCode {
ISO_A2_KIR => Ok(KIR),
ISO_A2_PRK => Ok(PRK),
ISO_A2_KOR => Ok(KOR),
ISO_A2_XKX => Ok(XKX),
ISO_A2_KWT => Ok(KWT),
ISO_A2_KGZ => Ok(KGZ),
ISO_A2_LAO => Ok(LAO),
Expand Down Expand Up @@ -1853,8 +1859,8 @@ impl CountryCode {
/// Attempts to determine the ISO 3166-1 CountryCode for the given three-character string,
/// assuming it is in upper-case characters
pub fn for_alpha3(value: &str) -> Result<CountryCode, CountryCodeParseErr> {
use CountryCode::*;
use alpha3::*;
use CountryCode::*;
match value {
ISO_A3_AFG => Ok(AFG),
ISO_A3_ALA => Ok(ALA),
Expand Down Expand Up @@ -1975,6 +1981,7 @@ impl CountryCode {
ISO_A3_KIR => Ok(KIR),
ISO_A3_PRK => Ok(PRK),
ISO_A3_KOR => Ok(KOR),
ISO_A3_XKX => Ok(XKX),
ISO_A3_KWT => Ok(KWT),
ISO_A3_KGZ => Ok(KGZ),
ISO_A3_LAO => Ok(LAO),
Expand Down Expand Up @@ -2120,8 +2127,8 @@ impl CountryCode {

/// Attempts to determine the ISO 3166-1 CountryCode for the given unsigned integer
pub fn for_id(value: u32) -> Result<CountryCode, CountryCodeParseErr> {
use CountryCode::*;
use numeric::*;
use CountryCode::*;
match value {
ISO_NUM_AFG => Ok(AFG),
ISO_NUM_ALA => Ok(ALA),
Expand Down Expand Up @@ -2242,6 +2249,7 @@ impl CountryCode {
ISO_NUM_KIR => Ok(KIR),
ISO_NUM_PRK => Ok(PRK),
ISO_NUM_KOR => Ok(KOR),
ISO_NUM_XKX => Ok(XKX),
ISO_NUM_KWT => Ok(KWT),
ISO_NUM_KGZ => Ok(KGZ),
ISO_NUM_LAO => Ok(LAO),
Expand Down Expand Up @@ -2446,15 +2454,19 @@ impl Display for CountryCode {
struct CountryCodeVisitor;

impl Serialize for CountryCode {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(self.alpha2())
}
}

impl<'de> Deserialize<'de> for CountryCode {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_str(CountryCodeVisitor)
}
}
Expand All @@ -2467,8 +2479,8 @@ impl<'de> Visitor<'de> for CountryCodeVisitor {
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: de::Error,
where
E: de::Error,
{
match CountryCode::for_alpha2_caseless(v) {
Ok(x) => Ok(x),
Expand All @@ -2477,8 +2489,8 @@ impl<'de> Visitor<'de> for CountryCodeVisitor {
}

fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: de::Error,
where
E: de::Error,
{
match CountryCode::for_alpha2_caseless(v) {
Ok(x) => Ok(x),
Expand Down
1 change: 1 addition & 0 deletions src/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub const ISO_NUM_KEN: u32 = 404;
pub const ISO_NUM_KIR: u32 = 296;
pub const ISO_NUM_PRK: u32 = 408;
pub const ISO_NUM_KOR: u32 = 410;
pub const ISO_NUM_XKX: u32 = 383;
pub const ISO_NUM_KWT: u32 = 414;
pub const ISO_NUM_KGZ: u32 = 417;
pub const ISO_NUM_LAO: u32 = 418;
Expand Down
Loading