Asia Crate
The asia crate provides a rich enumeration of Asian countries and their subregions, with functionality similar to the europe crate. It includes:
- A comprehensive
AsiaRegionenum representing both individual countries and subdivided countries. - Conversion traits to convert between
AsiaRegionand standard ISO country codes. - Round-trip conversions from
AsiaRegiontoCountry(from a sharedcountrycrate) and back. - Serialization/Deserialization (Serde) support for
AsiaRegionand its subregions, including nested subregions likeChinaRegion,IndiaRegion,JapanRegion, andIndonesiaRegion. - Exhaustive test suites ensuring correctness and stability.
Features
- No unsafe code: The codebase is entirely safe Rust.
- No
unwraporexpect: All error handling is done gracefully withResultand custom error types. - No
thiserror: Error handling is implemented manually for full control and consistency.
Examples
Convert a AsiaRegion to a Country:
use ;
use TryInto;
let region = Japan;
let country: Country = region.try_into.expect;
assert_eq!;
Convert a Country back to AsiaRegion:
use ;
use TryInto;
let country = India;
let region: AsiaRegion = country.try_into.expect;
assert!;
Serialize and deserialize AsiaRegion with JSON:
use AsiaRegion;
use ChinaRegion;
use serde_json;
let region = China;
let json = to_string.expect;
assert!;
assert!;
let deser: AsiaRegion = from_str.expect;
assert_eq!;
Error Handling
When attempting conversions that are not possible (e.g., mapping a combined region like GCC States to a single Country), a custom error type AsiaRegionConversionError is returned, allowing you to handle these cases gracefully.
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
License
This project is licensed under the MIT license. See LICENSE for details.