central-america

Crates.iocentral-america
lib.rscentral-america
version
sourcesrc
created_at2024-12-19 07:09:31.458226
updated_at2025-02-06 22:50:33.07446
descriptionA Rust crate providing enums and conversions for Central American countries and their subregions, analogous to the asia and europe crates.
homepage
repositoryhttps://github.com/klebs6/klebs-general
max_upload_size
id1488855
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`
size0
(klebs6)

documentation

https://docs.rs/central-america

README

Central America Crate

The central-america crate provides enums and conversions for Central American and nearby Caribbean countries and their combined region (Haiti and Dominican Republic), analogous to the asia, europe, and south-america crates.

Features

  • Comprehensive Enum: CentralAmericaRegion includes countries like Belize, Costa Rica, Nicaragua, and a combined region for Haiti and the Dominican Republic.
  • Conversions: Easily convert CentralAmericaRegion to Country (from a shared country crate), Iso3166Alpha2, Iso3166Alpha3, and CountryCode.
  • Serialization/Deserialization: Serde support allows serializing and deserializing CentralAmericaRegion to/from JSON, including combined regions.
  • Safe and Strict: No unsafe, no unwrap, and no thiserror. Errors are handled with custom error types.

Examples

Convert CentralAmericaRegion to Country:

use central_america::{CentralAmericaRegion, Country};
use std::convert::TryInto;

let region = CentralAmericaRegion::CostaRica;
let country: Country = region.try_into().expect("Should map to Costa Rica");
assert_eq!(country.to_string(), "Costa Rica");

Convert Country back to CentralAmericaRegion:

use central_america::{CentralAmericaRegion, Country};
use std::convert::TryInto;

let country = Country::Haiti;
let region: CentralAmericaRegion = country.try_into().expect("Should map to Haiti and Dominican Republic combined region");
assert_eq!(region, CentralAmericaRegion::HaitiAndDominicanRepublic);

Serialize and deserialize:

use central_america::CentralAmericaRegion;
use serde_json;

let region = CentralAmericaRegion::ElSalvador;
let json = serde_json::to_string(&region).expect("serialize");
assert!(json.contains("\"country\":\"El Salvador\""));

let deser: CentralAmericaRegion = serde_json::from_str(&json).expect("deserialize");
assert_eq!(deser, region);

Error Handling

If you attempt to convert a Country not represented in Central America to a CentralAmericaRegion, you get a CentralAmericaRegionConversionError. Similarly, no unwrap or expect are used internally.

Contributing

Contributions, issues, and feature requests are welcome! Check the issues page.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit changes: git commit -am 'Add some feature'
  4. Push: git push origin my-new-feature
  5. Submit a pull request

License

Licensed under the MIT license. See LICENSE for details.

Commit count: 357

cargo fmt