Crates.io | south-america |
lib.rs | south-america |
version | |
source | src |
created_at | 2024-12-19 06:59:20.264368 |
updated_at | 2025-02-06 22:51:52.644493 |
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 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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-feature
git commit -am 'Add some feature'
git push origin my-new-feature
Licensed under the MIT license. See LICENSE for details.