# Lipi Lekhika โ Rust
> A high-performance transliteration library for Indian Brahmic scripts
[](https://crates.io/crates/lipilekhika)
[](https://crates.io/crates/lipilekhika)
[](https://github.com/shubhattin/lipilekhika/actions/workflows/rust_ci.yml)
[](https://opensource.org/licenses/MIT)
๐ **[Website](https://lipilekhika.in)** โข ๐ **[Documentation](https://lipilekhika.in/getting-started/rust)** โข ๐ฆ **[Crates.io](https://crates.io/crates/lipilekhika)** โข ๐ **[Changelog](./CHANGELOG.md)**
---
## โจ Features
- ๐ **Bidirectional Transliteration** โ Convert between 15+ Indian Brahmic scripts
- โก **High Performance** โ Zero-overhead abstractions and optimized algorithms
- ๐ก๏ธ **Type Safe** โ Leverages Rust's type system for safety and correctness
- ๐ฏ **Customizable Options** โ Fine-tune transliteration and typing behaviour
- โจ๏ธ **Typing Mode** โ Stateful context for real-time character-by-character input
- ๐ฆ **Embedded Script Data** โ All script data bundled at compile time
## ๐ฅ Installation
```bash
cargo add lipilekhika
```
## ๐ Quick Start
### Basic Transliteration
```rust
use lipilekhika::transliterate;
fn main() {
let result = transliterate(
"namaskAraH",
"Normal",
"Devanagari",
None
).unwrap();
println!("{}", result); // เคจเคฎเคธเฅเคเคพเคฐเค
}
```
### With Custom Options
```rust
use lipilekhika::transliterate;
use std::collections::HashMap;
fn main() {
let mut options = HashMap::new();
options.insert(
"brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra".to_string(),
true
);
let result = transliterate(
"เฐเฐเฐเฐพ",
"Telugu",
"Gujarati",
Some(&options)
).unwrap();
println!("{}", result); // เชเชเชเชพ (instead of เชเชเซเชเชพ)
}
```
## ๐ API
### Core Functions
#### `transliterate`
```rust
pub fn transliterate(
text: &str,
from: &str,
to: &str,
trans_options: Option<&HashMap<String, bool>>,
) -> Result<String, String>
```
Transliterates text from one script to another.
**Parameters:**
- `text` โ Text to transliterate
- `from` โ Source script/language name (e.g., "Normal", "Devanagari", "Telugu")
- `to` โ Target script/language name
- `trans_options` โ Optional custom transliteration options
**Returns:** `Result<String, String>` โ Transliterated text or error message
#### `get_all_option`
```rust
pub fn get_all_option(
from_script_name: &str,
to_script_name: &str,
) -> Result<Vec<String>, String>
```
Gets all available custom options for a script pair.
**Parameters:**
- `from_script_name` โ Source script/language name
- `to_script_name` โ Target script/language name
**Returns:** `Result<Vec<String>, String>` โ List of option keys or error message
#### `get_script_typing_data_map`
```rust
pub fn get_script_typing_data_map(
script: &str,
) -> Result<ScriptTypingDataMap, String>
```
Gets typing data mappings for a script (for building custom input methods).
**Parameters:**
- `script` โ Script/language name
**Returns:** `Result<ScriptTypingDataMap, String>` โ Typing data or error message
### Typing Module
For character-by-character real-time input:
```rust
use lipilekhika::typing::{TypingContext, TypingContextOptions};
fn main() {
let mut ctx = TypingContext::new("Devanagari", None).unwrap();
// Process character-by-character input
let diff = ctx.take_key_input("n").unwrap();
println!("Delete: {}, Add: '{}'", diff.to_delete_chars_count, diff.diff_add_text);
let diff = ctx.take_key_input("a").unwrap();
println!("Delete: {}, Add: '{}'", diff.to_delete_chars_count, diff.diff_add_text);
// Clear context when needed
ctx.clear_context();
}
```
#### Types
- **`TypingContext`** โ Stateful context for typing mode
- `new(typing_lang: &str, options: Option<TypingContextOptions>)` โ Create new context
- `take_key_input(&mut self, key: &str)` โ Process single character input
- `clear_context(&mut self)` โ Clear internal state
- **`TypingContextOptions`** โ Configuration for typing behavior
- `auto_context_clear_time_ms: u64` โ Auto-clear timeout (default: 4500ms)
- `use_native_numerals: bool` โ Use script-native numerals (default: true)
- `include_inherent_vowel: bool` โ Include inherent vowel/schwa (default: false)
- **`TypingDiff`** โ Result of processing a key input
- `to_delete_chars_count: usize` โ Characters to delete from current state
- `diff_add_text: String` โ Text to insert
- **`ScriptTypingDataMap`** โ Typing data for a script (from `get_script_typing_data_map`)
- `common_krama_map: Vec<TypingDataMapItem>` โ Common character mappings
- `script_specific_krama_map: Vec<TypingDataMapItem>` โ Script-specific mappings
- **`ListType`** โ Character type enum: `Anya`, `Vyanjana`, `Matra`, `Svara`
- **`TypingDataMapItem`** โ Type alias for `(String, ListType, Vec<String>)`
## ๐ฏ Supported Scripts
Devanagari, Bengali, Tamil, Telugu, Kannada, Malayalam, Gujarati, Odia, Gurmukhi, Sinhala, Tamil-Extended, Myanmar, Tibetan, Limbu, and more.
๐ Full list: [lipilekhika.in/reference/supported_scripts](https://lipilekhika.in/reference/supported_scripts)
## ๐ง Custom Options
See the full list of custom transliteration options:
๐ [lipilekhika.in/reference/custom_trans_options](https://lipilekhika.in/reference/custom_trans_options)
## ๐ Resources
- **[Website](https://lipilekhika.in)** โ Documentation and guides
- **[Supported Scripts](https://lipilekhika.in/reference/supported_scripts)** โ Full list of scripts
- **[Custom Options](https://lipilekhika.in/reference/custom_trans_options)** โ Transliteration options reference
- **[GitHub Repository](https://github.com/shubhattin/lipilekhika)** โ Source code and issues
## ๐ License
MIT License โ See [LICENSE](./LICENCE) for details