translit

Struct Transliterator

Source
pub struct Transliterator { /* private fields */ }
Expand description

The Transliterator struct allows for the transliteration of the string of characters of Cyrillic alphabet UTF-8 to Latin alphabet and back.

Implementations§

Source§

impl Transliterator

Source

pub fn new(custom_rules: CharsMapping) -> Self

Creates a new Transliterator with transliteration table

Examples


use translit::{Transliterator, CharsMapping};
let table: CharsMapping =
[
("а", "a"),
("с", "s"),
("д", "d"),
("ф", "f"),
].iter()
  .cloned()
  .collect();

let trasliterator = Transliterator::new(table);
let res = trasliterator.convert("фасад", false);
assert_eq!("fasad", res);
Examples found in repository?
examples/web-gost779.rs (line 28)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let v: CharsMapping = [
        (" ", "-"),
        (",", ""),
        (":", ""),
        (";", ""),
        ("№", ""),
        ("ь", ""),
        ("ъ", ""),
        ("Ы", "Y"),
        ("Э", "E"),
        ("ы", "y"),
        ("э", "e"),
    ]
    .iter()
    .cloned()
    .collect();

    let mut custom_table = gost779b_ru();
    custom_table.retain(|&x| !x.1.contains("`"));
    custom_table.retain(|&x| !x.1.contains("#"));
    custom_table.extend(v.iter());

    let trn = Transliterator::new(custom_table);

    let source =
        "Общие вопросы по языку, получение помощи".to_lowercase();

    assert_eq!(
        "obshhie-voprosy-po-yazyku-poluchenie-pomoshhi",
        trn.to_latin(&source)
    );
}
Source

pub fn convert(&self, src: &str, invert: bool) -> String

Transliterate input string.

Trait Implementations§

Source§

impl FromLatin for Transliterator

Source§

fn from_latin(&self, src: &str) -> String

The wrapper on the method convert of transliteration from the Latin alphabet

Source§

impl ToLatin for Transliterator

Source§

fn to_latin(&self, src: &str) -> String

The wrapper on the method convert of transliteration in the Latin alphabet

Auto Trait Implementations§

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.