1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::codegen;
use crate::continents::Continent;
use std::fmt::{Display, Formatter};
codegen!(statement; "countries-enum-values");
impl Country {
pub fn from_buffer(value: u8) -> Option<Self> {
codegen!("countries-from-buffer")
}
/// ```rust
/// use ipcap::countries::Country;
/// let country = Country::Poland;
///
/// assert_eq!(country.alphabetic_code_2(), "PL")
/// ```
pub fn alphabetic_code_2(&self) -> &'static str {
codegen!("countries-codes-2")
}
/// ```rust
/// use ipcap::countries::Country;
/// let country = Country::Poland;
///
/// assert_eq!(country.alphabetic_code_3(), "POL")
/// ```
pub fn alphabetic_code_3(&self) -> &'static str {
codegen!("countries-codes-3")
}
/// ```rust
/// use ipcap::countries::Country;
///
/// assert_eq!(Country::from_alphabetic_code_2("PL"), Some(Country::Poland))
/// ```
pub fn from_alphabetic_code_2(value: &str) -> Option<Self> {
codegen!("countries-codes-2-reverse")
}
/// ```rust
/// use ipcap::countries::Country;
///
/// assert_eq!(Country::from_alphabetic_code_3("POL"), Some(Country::Poland))
/// ```
pub fn from_alphabetic_code_3(value: &str) -> Option<Self> {
codegen!("countries-codes-3-reverse")
}
/// ```rust
/// use ipcap::continents::Continent;
/// use ipcap::countries::Country;
///
/// assert_eq!(Country::Poland.continent(), Some(Continent::Europe))
/// ```
pub fn continent(&self) -> Option<Continent> {
self.into()
}
}
impl Display for Country {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
codegen!("countries-to-names")
}
}