ipcap/
continents.rs

1use crate::codegen;
2use crate::countries::Country;
3use std::fmt::{Display, Formatter};
4
5#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
6pub enum Continent {
7    Africa,
8    Antarctica,
9    Asia,
10    Europe,
11    NorthAmerica,
12    Oceania,
13    SouthAmerica,
14}
15
16impl Continent {
17    pub fn alphabetic_code_2(&self) -> &'static str {
18        match self {
19            Continent::Africa => "AF",
20            Continent::Antarctica => "AN",
21            Continent::Asia => "AS",
22            Continent::Europe => "EU",
23            Continent::NorthAmerica => "NA",
24            Continent::Oceania => "OC",
25            Continent::SouthAmerica => "SA",
26        }
27    }
28}
29
30impl Display for Continent {
31    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Continent::Africa => f.write_str("Africa"),
34            Continent::Antarctica => f.write_str("Antarctica"),
35            Continent::Asia => f.write_str("Asia"),
36            Continent::Europe => f.write_str("Europe"),
37            Continent::NorthAmerica => f.write_str("North America"),
38            Continent::Oceania => f.write_str("Oceania"),
39            Continent::SouthAmerica => f.write_str("South America"),
40        }
41    }
42}
43
44impl From<&Country> for Option<Continent> {
45    fn from(value: &Country) -> Self {
46        codegen!("country-to-continent")
47    }
48}