| Crates.io | asia |
| lib.rs | asia |
| version | 0.6.0 |
| created_at | 2024-12-19 06:42:45.331392+00 |
| updated_at | 2025-02-06 22:57:45.798883+00 |
| description | A Rust crate providing enums and conversions for Asian countries and their subregions, analogous to the Europe crate. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1488838 |
| size | 129,448 |
The asia crate provides a rich enumeration of Asian countries and their subregions, with functionality similar to the europe crate. It includes:
AsiaRegion enum representing both individual countries and subdivided countries.AsiaRegion and standard ISO country codes.AsiaRegion to Country (from a shared country crate) and back.AsiaRegion and its subregions, including nested subregions like ChinaRegion, IndiaRegion, JapanRegion, and IndonesiaRegion.unwrap or expect: All error handling is done gracefully with Result and custom error types.thiserror: Error handling is implemented manually for full control and consistency.Convert a AsiaRegion to a Country:
use asia::{AsiaRegion, Country};
use std::convert::TryInto;
let region = AsiaRegion::Japan(asia::JapanRegion::Hokkaido);
let country: Country = region.try_into().expect("Should map to Japan");
assert_eq!(country.to_string(), "Japan");
Convert a Country back to AsiaRegion:
use asia::{AsiaRegion, Country};
use std::convert::TryInto;
let country = Country::India;
let region: AsiaRegion = country.try_into().expect("Should map to India");
assert!(matches!(region, AsiaRegion::India(_)));
Serialize and deserialize AsiaRegion with JSON:
use asia::AsiaRegion;
use asia::ChinaRegion;
use serde_json;
let region = AsiaRegion::China(ChinaRegion::Beijing);
let json = serde_json::to_string(®ion).expect("serialize");
assert!(json.contains("\"country\":\"China\""));
assert!(json.contains("\"region\":\"Beijing\""));
let deser: AsiaRegion = serde_json::from_str(&json).expect("deserialize");
assert_eq!(deser, region);
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.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
git checkout -b my-new-featuregit commit -am 'Add some feature'git push origin my-new-featureThis project is licensed under the MIT license. See LICENSE for details.