| Crates.io | south-america |
| lib.rs | south-america |
| version | 0.6.0 |
| created_at | 2024-12-19 06:59:20.264368+00 |
| updated_at | 2025-02-06 22:51:52.644493+00 |
| description | A Rust crate providing enums and conversions for South American countries and their subregions, analogous to the asia and europe crates. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1488848 |
| size | 86,890 |
The south-america crate provides enums and conversions for South American countries and their subregions, analogous to the asia and europe crates. It includes:
SouthAmericaRegion enum representing South American countries, including subdivided regions for Brazil.SouthAmericaRegion and standard ISO country codes.SouthAmericaRegion to Country (from a shared country crate) and back.SouthAmericaRegion and its subregions (like BrazilRegion).Result and custom error types.Convert a SouthAmericaRegion to a Country:
use south_america::{SouthAmericaRegion, Country};
use std::convert::TryInto;
let region = SouthAmericaRegion::Brazil(south_america::BrazilRegion::Sul);
let country: Country = region.try_into().expect("Should map to Brazil");
assert_eq!(country.to_string(), "Brazil");
Convert a Country back to SouthAmericaRegion:
use south_america::{SouthAmericaRegion, Country};
use std::convert::TryInto;
let country = Country::Argentina;
let region: SouthAmericaRegion = country.try_into().expect("Should map to Argentina");
assert_eq!(region, SouthAmericaRegion::Argentina);
Serialize and deserialize SouthAmericaRegion with JSON:
use south_america::{SouthAmericaRegion, BrazilRegion};
use serde_json;
let region = SouthAmericaRegion::Brazil(BrazilRegion::Nordeste);
let json = serde_json::to_string(®ion).expect("serialize");
assert!(json.contains("\"country\":\"Brazil\""));
assert!(json.contains("\"region\":\"Nordeste\""));
let deser: SouthAmericaRegion = serde_json::from_str(&json).expect("deserialize");
assert_eq!(deser, region);
If attempting impossible conversions (e.g., non-South American countries to SouthAmericaRegion), an SouthAmericaRegionConversionError is returned.
Contributions, issues, and feature requests are welcome! Check the issues page.
git checkout -b my-new-featuregit commit -am 'Add some feature'git push origin my-new-featureLicensed under the MIT license. See LICENSE for details.