#region #countries #geography #oceania #rust

australia-oceania-antarctica

A Rust crate providing enums and conversions for Australian, Oceanian countries, Antarctica and their subregions, analogous to the Europe crate

2 unstable releases

new 0.2.0 Dec 19, 2024
0.1.0 Dec 19, 2024

#5 in #regions

MIT license

105KB
1.5K 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 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).

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(&region)?;
    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

~2.7–3.5MB
~75K SLoC