pub struct Louis { /* private fields */ }Expand description
A singleton that handles all access to liblouis.
This struct is needed since liblouis is thread-unsafe and can only be called from one thread at a time.
It is Send, but !Sync, so that at any given moment, all &s to it live on the same thread,
but if you own it you can move it across threads. All liblouis calls therefore need a & to this.
It also provides some convenient setup/teardown logic:
- When created, it registers a logging callback with liblouis that pipes all messages into the log.rs facade with the appropriate log levels set
- When dropped, it resets liblouis’ logging behaviour to the default and calls
lou_free()to make sure no memory is leaked.
Implementations§
Source§impl Louis
impl Louis
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Tries to initialize liblouis, returning Some(Louis) on success.
On failure, it returns None, indicating that the ThreadUnsafetyToken has already been taken.
Sourcepub fn version(&self) -> Result<Version, SemVerError>
pub fn version(&self) -> Result<Version, SemVerError>
Returns the version of liblouis that this crate is linked against
Sourcepub fn list_tables(&self) -> Vec<String>
pub fn list_tables(&self) -> Vec<String>
Lists the filenames of all the tables that are available
Sourcepub fn translate_simple(
&self,
table_names: &str,
input: &str,
backwards: bool,
mode: TranslationModes,
) -> String
pub fn translate_simple( &self, table_names: &str, input: &str, backwards: bool, mode: TranslationModes, ) -> String
Translates the text in input according to the tables given by table_names
§Examples
Pass mode=0 for regular translation:
let louis = Louis::new().unwrap();
let brl = louis.translate_simple("ru.tbl", "Я понимаю", false, 0);
assert_eq!(brl, "$ PONIMA|");You can also translate directly to Unicode Braille dots:
let dots = louis.translate_simple("sr.tbl", "Добродошли", false, DOTS_UNICODE);
assert_eq!(dots, "⠨⠙⠕⠃⠗⠕⠙⠕⠱⠇⠊");Pass backwards=true for backtranslation:
let dots = "⠠⠭ ⠐⠺⠎⠖";
let txt = louis.translate_simple("en_US.tbl", dots, true, 0);
assert_eq!(txt, "It works!");To use multiple tables, pass them as a comma-separated list:
let txt = "This is another way to make dots.";
let dots = louis.translate_simple("unicode.dis,en_US.tbl", txt, false, 0);
assert_eq!(dots, "⠠⠹ ⠊⠎ ⠁⠝⠕⠮⠗ ⠺⠁⠽ ⠖⠍⠁⠅⠑ ⠙⠕⠞⠎⠲");