codes_un_m49/lib.rs
1/*!
2This package contains an implementation of the [UN
3M49](https://unstats.un.org/unsd/methodology/m49) Standard Country or Area
4Codes for Statistical Use (Series M, No. 49) specification.
5
6UN M49 or the Standard Country or Area Codes for Statistical Use (Series M,
7No. 49) is a standard for area codes used by the United Nations for
8statistical purposes, developed and maintained by the United Nations
9Statistics Division. Each area code is a 3-digit number which can refer to a
10wide variety of geographical and political regions, like a continent and a
11country. Codes assigned in the system generally do not change when the country
12or area's name changes (unlike ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3), but
13instead change when the territorial extent of the country or area changes
14significantly, although there have been exceptions to this rule.
15
16# Example
17
18```rust
19use codes_un_m49 as M49;
20
21let region = M49::UN_M69_REGION_258;
22
23assert_eq!(region.code(), 258);
24assert_eq!(region.name(), "French Polynesia");
25assert_eq!(region.kind(), M49::RegionKind::Country);
26
27// feature = "country_codes"
28// assert_eq!(parent.country_code(), Some(CountryCode::PF));
29// or
30// assert_eq!(region.country_code(), Some("PF"));
31
32let parent = region.parent_code().unwrap();
33assert_eq!(parent.code(), 61);
34assert_eq!(parent.name(), "Polynesia");
35
36let parent = parent.parent_code().unwrap();
37assert_eq!(parent.code(), 9);
38assert_eq!(parent.name(), "Oceania");
39
40let parent = parent.parent_code().unwrap();
41assert_eq!(parent.code(), 1);
42assert_eq!(parent.name(), "World");
43```
44
45# Features
46
47By default only the `serde` feature is enabled.
48
49* `serde` - Enables serialization of the [RegionClassificationCode] type.
50* `country_codes`; if enabled the value returned by the [RegionClassificationCode::country_code]
51 method will be an instance of `CountryCode` from the `codes-iso-3166`
52 package, otherwise it returns `'static str`.
53
54*/
55
56#![warn(
57 unknown_lints,
58 // ---------- Stylistic
59 absolute_paths_not_starting_with_crate,
60 elided_lifetimes_in_paths,
61 explicit_outlives_requirements,
62 macro_use_extern_crate,
63 nonstandard_style, /* group */
64 noop_method_call,
65 rust_2018_idioms,
66 single_use_lifetimes,
67 trivial_casts,
68 trivial_numeric_casts,
69 // ---------- Future
70 future_incompatible, /* group */
71 rust_2021_compatibility, /* group */
72 // ---------- Public
73 missing_debug_implementations,
74 // missing_docs,
75 unreachable_pub,
76 // ---------- Unsafe
77 unsafe_code,
78 unsafe_op_in_unsafe_fn,
79 // ---------- Unused
80 unused, /* group */
81)]
82#![deny(
83 // ---------- Public
84 exported_private_dependencies,
85 private_in_public,
86 // ---------- Deprecated
87 anonymous_parameters,
88 bare_trait_objects,
89 ellipsis_inclusive_range_patterns,
90 // ---------- Unsafe
91 deref_nullptr,
92 drop_bounds,
93 dyn_drop,
94)]
95
96// ------------------------------------------------------------------------------------------------
97//
98// The rest of this file is generated by the package build script.
99//
100// ------------------------------------------------------------------------------------------------
101
102include!(concat!(env!("OUT_DIR"), "/generated.rs"));
103
104// ------------------------------------------------------------------------------------------------
105// Modules
106// ------------------------------------------------------------------------------------------------
107
108#[doc(hidden)]
109mod kinds;
110pub use kinds::RegionKind;