Crates.io | europe |
lib.rs | europe |
version | |
source | src |
created_at | 2024-12-19 03:57:22.943325 |
updated_at | 2025-02-06 22:47:50.173284 |
description | A comprehensive Rust crate for enumerating and working with European countries and their subdivisions. |
homepage | https://github.com/yourusername/europe |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1488766 |
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 |
europe is a Rust crate for enumerating and working with European countries and their subdivisions. It provides a comprehensive set of enums representing European countries, as well as nested enums for various regions, provinces, and federations within those countries. The crate supports serialization and deserialization with serde
, enabling seamless integration with JSON and other formats, while preserving region-specific details.
Comprehensive Geographical Coverage:
Includes a wide range of European countries and their respective regions (like France’s regions, Germany’s Bundesländer, Italy’s regions, etc.).
Nested Regions:
Subdivided countries are represented as enum variants containing region-level enums (e.g., EuropeRegion::France(FranceRegion::Bretagne)
).
Serialization/Deserialization:
Uses serde
for serialization and deserialization. In non-abbreviation mode, subdivided countries are serialized as structured maps ({ "country": "France", "region": "Bretagne" }
), ensuring lossless round-trips of region data.
Abbreviations (Optional):
With the serde_abbreviation
feature, regions are serialized to their abbreviation codes (e.g., FR
for France, GB
for the UK, DE
for Germany’s regions, etc.).
Reliable Parsing:
Invalid input during deserialization leads to descriptive DeError::unknown_variant
errors. Default values are defined for subdivided regions, ensuring that if a region field is missing, the default region is used.
Add this to your Cargo.toml
:
[dependencies]
europe = "0.1"
Then in your code:
use europe::{EuropeRegion, FranceRegion};
use serde_json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let region = EuropeRegion::France(FranceRegion::Bretagne);
let serialized = serde_json::to_string(®ion)?;
println!("Serialized: {}", serialized);
let deserialized: EuropeRegion = serde_json::from_str(&serialized)?;
assert_eq!(deserialized, region);
println!("Deserialized matches original!");
Ok(())
}
The crate includes an extensive set of tests covering:
Run the tests using:
cargo test
All tests should pass.
This project is licensed under the MIT license (or your chosen license). See LICENSE for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.