| Crates.io | australia-oceania-antarctica |
| lib.rs | australia-oceania-antarctica |
| version | 0.5.0 |
| created_at | 2024-12-19 17:27:44.888173+00 |
| updated_at | 2025-02-06 22:41:30.133517+00 |
| description | A Rust crate providing enums and conversions for Australian, Oceanian countries, Antarctica and their subregions, analogous to the Europe crate. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1489373 |
| size | 83,808 |
The australia-oceania-antarctica crate provides an enumeration of countries and special regions in the Australia/Oceania/Antarctica area, analogous to the africa crate.
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 to Country 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).
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(())
}
Run the tests with:
cargo test
This project is licensed under the MIT License - see the LICENSE file for details.