yosina/
lib.rs

1#![doc = include_str!("../README.md")]
2
3pub mod char;
4#[cfg(not(feature = "codegen"))]
5pub mod recipes;
6pub mod transliterator;
7pub mod transliterators;
8
9pub use char::*;
10pub use transliterator::*;
11
12#[cfg(not(feature = "codegen"))]
13pub use recipes::TransliterationRecipe;
14pub use transliterators::TransliteratorConfig;
15
16/// Frontend convenience function to create a string-to-string transliterator from a recipe or a list of configs.
17///
18/// This is the main entry point for the library. It accepts either a recipe or a list of transliterator configs
19/// and returns a function that can transliterate strings.
20///
21/// # Arguments
22///
23/// * `configs_or_recipe` - Either a vector of configs/strings or a TransliterationRecipe
24///
25/// # Returns
26///
27/// A function that takes a string and returns a transliterated string
28#[cfg(not(feature = "codegen"))]
29pub fn make_transliterator(
30    factory: &impl TransliteratorFactory,
31) -> Result<impl Fn(&str) -> Result<String, TransliterationError>, TransliteratorFactoryError> {
32    let tl = factory.new_transliterator()?;
33
34    Ok(move |input: &str| -> Result<String, TransliterationError> {
35        let mut pool = CharPool::new();
36        let chars = pool.build_char_array(input);
37        let transliterated = tl.transliterate(&mut pool, &chars)?;
38        Ok(from_chars(transliterated.iter().cloned()))
39    })
40}