5 releases (breaking)
0.5.0 | Feb 6, 2025 |
---|---|
0.4.0 | Feb 2, 2025 |
0.3.0 | Jan 31, 2025 |
0.2.0 | Dec 19, 2024 |
0.1.0 | Dec 19, 2024 |
#8 in #regions
407 downloads per month
Used in world-region
145KB
2K
SLoC
australia-oceania-antarctica Crate
The australia-oceania-antarctica
crate provides an enumeration of countries and special regions in the Australia/Oceania/Antarctica area, analogous to the africa
crate.
Features
-
Comprehensive Enumeration: Includes Australia, numerous island states in Oceania, and Antarctica, as well as special territories like French Polynesia and Niue.
-
Conversions to/from
Country
: Converts region variants toCountry
where possible. Returns detailed errors for unsupported territories or combined regions. -
ISO Codes and Abbreviations: Each variant can produce abbreviations, and when converting to
Country
you can obtain ISO codes (if a direct mapping exists). -
Serialization/Deserialization: Supports
serde
for easy serialization to and from JSON:{ "country": "Samoa" }
deserializes back into
AustraliaOceaniaAntarcticaRegion::Samoa
. -
Error Handling: Employs robust error handling returning typed errors (
AoaRegionConversionError
).
Example
use australia_oceania_antarctica::AustraliaOceaniaAntarcticaRegion;
use std::convert::TryInto;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let region = AustraliaOceaniaAntarcticaRegion::NewZealand;
let country = region.try_into()?; // Convert to Country
println!("Country: {:?}", country);
let json = serde_json::to_string(®ion)?;
println!("Serialized: {}", json);
let deserialized: AustraliaOceaniaAntarcticaRegion = serde_json::from_str(&json)?;
println!("Deserialized: {:?}", deserialized);
Ok(())
}
Testing
Run the tests with:
cargo test
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~13–26MB
~367K SLoC