lang_code/lib.rs
1//! Language code library
2//!
3//!## Features
4//!
5//!- `lang-name` - Adds language name to the dataset
6//!
7//!## Data source
8//!
9//!Code is generated using python library [iso639](https://github.com/LBeaudoux/iso639)
10
11#![no_std]
12#![warn(missing_docs)]
13#![cfg_attr(feature = "cargo-clippy", allow(clippy::style))]
14
15mod data;
16pub use data::{Lang, DATA};
17
18#[derive(Copy, Clone, Debug, PartialEq, Eq)]
19///Language
20pub struct Language {
21 #[cfg(feature = "lang-name")]
22 ///Full name of the language
23 ///
24 ///Only available if lang-name feature is enabled
25 name: &'static str,
26 ///ISO639-1 2 letter code
27 part1: &'static str,
28 ///ISO639-3 3 letter code
29 part3: &'static str,
30}
31
32impl Language {
33 #[cfg(feature = "lang-name")]
34 ///Full name of the language
35 ///
36 ///Only available if lang-name feature is enabled
37 pub const fn name(&self) -> &'static str {
38 self.name
39 }
40
41 ///Returns ISO639-1 2 letter code, if language has any
42 pub const fn iso639_1(&self) -> Option<&'static str> {
43 if self.part1.is_empty() {
44 None
45 } else {
46 Some(self.part1)
47 }
48 }
49
50 ///Returns ISO639-3 3 letter code
51 pub const fn iso639_3(&self) -> &'static str {
52 self.part3
53 }
54}