jp_prefecture/
lib.rs

1//! # Overview
2//! jp-prefecture is an utility library for handling Japanese prefectures.
3//!
4//! # Getting Started
5//! Crate has to be added as dependency to `Cargo.toml`
6//! ```toml
7//! [dependencies]
8//! jp-prefecture = "3.1.0"
9//! ```
10//! and imported to the scope of a block where it's begin called
11//! ```rust
12//! use jp_prefecture::prefectures;
13//! ```
14//!
15//! # Examples
16//! ```
17//! use jp_prefecture::prefectures;
18//!
19//! let tokyo = prefectures::find_by_kanji("東京都");
20//! println!("{:?}", tokyo); // => Ok(Prefecture::Tokyo)
21//! println!("{:?}", tokyo.as_ref().unwrap().kanji()); // => "東京都"
22//! println!("{:?}", tokyo.as_ref().unwrap().kanji_short()); // => "東京"
23//! println!("{:?}", tokyo.as_ref().unwrap().english()); // => "Tokyo"
24//!
25//! let tokyo = prefectures::find_by_kanji("東京県"); // uhmmmm...
26//! println!("{:?}", tokyo); // => Err(Error::InvalidPrefectureName("東京県"))
27//! ```
28
29mod mapping;
30pub mod prefectures;
31
32/// Enum representing errors related to Japanese prefectures
33#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
34pub enum Error {
35    /// The prefecture code cannot be parsed or is invalid
36    #[error("Invalid prefecture code: {0}")]
37    InvalidPrefectureCode(u32),
38    /// The prefecture name cannot be parsed or is invalid
39    #[error("Invalid prefecture name: {0}")]
40    InvalidPrefectureName(String),
41}