#region #geography #administrative #api-bindings #philippines #development-tools-localization

ph-region

A library for managing and utilizing administrative regions of the Philippines

1 unstable release

0.1.0 Apr 28, 2024

#1 in #regions

MIT license

15KB
308 lines

PH Regions Rust Library

Rust

The ph-region Rust module provides a comprehensive way to manage and interact with a predefined set of regions, such as administrative regions in the Philippines. This module allows easy access to region details through various utility functions.

Features

  • List Region Details: You can list region codes, names, and abbreviations.
  • Parse from Strings: Convert string input into region enum instances.
  • Display Full Names and Codes: Easily retrieve full names or codes of regions for display purposes.
  • Key-Value Mapping: Get a mapping of region codes to names or full names to codes.

Installation

Add the following to your Cargo.toml file:

[dependencies]
ph-region = "0.1.0"

Replace "0.1.0" with the latest version of ph-region.

Usage

Listing Regions

You can list the keys, codes, or names of all regions:

use ph_region::region::Region;

fn main() {
    // Different way to List the Regions
    // list of keys
    println!("{:?}",Region::keys());
    // list of regions abbrev name
    println!("{:?}",Region::codes());
    // list of region name
    println!("{:?}",Region::names());
}

Parsing and Displaying Region Details

use ph_region::region::Region;

fn main() {
    // Parse a region from a string and print it if valid
    if let Some(region) = Region::from_str("ncr") {
        println!("Region parsed: {:?}", region);
        println!("Region name: {}", region.name());
    }

    // Display the full name of a region from a numeric code
    if let Some(region) = Region::from_str("1") {
        println!("Full name: {}", region.full_name());
    }
}

Key-Value Pairs

use ph_region::region::Region;

fn main() {
    // Display regions as code to name key-value pairs
    println!("{:?}", Region::list());

    // Display regions as name to code key-value pairs
    println!("{:?}", Region::list_by_full_name());
}

No runtime deps