Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
pemistahl committed Nov 6, 2023
1 parent 4bdc57d commit 15cf070
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ impl Display for Language {
}

impl Language {
/// Returns a set of all supported languages.
pub fn all() -> HashSet<Language> {
Language::iter().collect()
}

/// Returns a set of all supported spoken languages.
pub fn all_spoken_ones() -> HashSet<Language> {
Language::iter()
.filter(|it| {
Expand All @@ -294,42 +296,51 @@ impl Language {
.collect()
}

/// Returns a set of all languages supporting the Arabic script.
pub fn all_with_arabic_script() -> HashSet<Language> {
Language::iter()
.filter(|it| it.alphabets().contains(&Alphabet::Arabic))
.collect()
}

/// Returns a set of all languages supporting the Cyrillic script.
pub fn all_with_cyrillic_script() -> HashSet<Language> {
Language::iter()
.filter(|it| it.alphabets().contains(&Alphabet::Cyrillic))
.collect()
}

/// Returns a set of all languages supporting the Devanagari script.
pub fn all_with_devanagari_script() -> HashSet<Language> {
Language::iter()
.filter(|it| it.alphabets().contains(&Alphabet::Devanagari))
.collect()
}

/// Returns a set of all languages supporting the Latin script.
pub fn all_with_latin_script() -> HashSet<Language> {
Language::iter()
.filter(|it| it.alphabets().contains(&Alphabet::Latin))
.collect()
}

/// Returns the language associated with the ISO 639-1 code
/// passed to this method.
pub fn from_iso_code_639_1(iso_code: &IsoCode639_1) -> Language {
Language::iter()
.find(|it| &it.iso_code_639_1() == iso_code)
.unwrap()
}

/// Returns the language associated with the ISO 639-3 code
/// passed to this method.
pub fn from_iso_code_639_3(iso_code: &IsoCode639_3) -> Language {
Language::iter()
.find(|it| &it.iso_code_639_3() == iso_code)
.unwrap()
}

/// Returns the ISO 639-1 code of this language.
pub fn iso_code_639_1(&self) -> IsoCode639_1 {
match self {
#[cfg(feature = "afrikaans")]
Expand Down Expand Up @@ -559,6 +570,7 @@ impl Language {
}
}

/// Returns the ISO 639-3 code of this language.
pub fn iso_code_639_3(&self) -> IsoCode639_3 {
match self {
#[cfg(feature = "afrikaans")]
Expand Down
Loading

0 comments on commit 15cf070

Please sign in to comment.