Louis

Struct Louis 

Source
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

Source

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.

Source

pub fn version(&self) -> Result<Version, SemVerError>

Returns the version of liblouis that this crate is linked against

Source

pub fn list_tables(&self) -> Vec<String>

Lists the filenames of all the tables that are available

Source

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, "⠠⠹ ⠊⠎ ⠁⠝⠕⠮⠗ ⠺⠁⠽ ⠖⠍⠁⠅⠑ ⠙⠕⠞⠎⠲");

Trait Implementations§

Source§

impl Drop for Louis

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Louis

§

impl !RefUnwindSafe for Louis

§

impl Send for Louis

§

impl !Sync for Louis

§

impl Unpin for Louis

§

impl UnwindSafe for Louis

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.