stop_words/
lib.rs

1#![warn(clippy::all)]
2#![warn(missing_docs)]
3#![warn(clippy::missing_docs_in_private_items)]
4#![doc = include_str!("../README.md")]
5
6mod language_names;
7pub use crate::language_names::LANGUAGE;
8
9#[allow(clippy::missing_docs_in_private_items)]
10mod generated {
11    include!(concat!(env!("OUT_DIR"), "/stopwords.rs"));
12}
13
14use crate::generated::lookup;
15
16/// This function fetches stop words for a language using either a member of the `LANGUAGE` enum,
17/// or a two-character ISO language code as any type implementing [`std::convert::AsRef`]`<str>`.
18/// Please note that constructed languages use either a member of the `LANGUAGE` enum, or a
19/// __three__-character ISO language code as either a `str` or a `String` type.
20/// ```ignore
21/// let first_list = stop_words::get("ar");
22/// let second_list = stop_words::get(stop_words::LANGUAGE::Arabic);
23/// assert_eq!(first_list, second_list)
24/// ```
25/// # Panics
26///
27/// Panics if the provided language code is not recognized.
28pub fn get<T: std::convert::AsRef<str>>(input_language: T) -> &'static [&'static str] {
29    let language_name: &str = input_language.as_ref();
30    lookup(language_name).unwrap_or_else(|| {
31        panic!(
32            "The '{language_name}' language is not recognized. Please check the documentation for a supported list of languages."
33        )
34    })
35}