bamboo-core 0.3.8

Vietnamese input method engine written in Rust
Documentation

Bamboo Core (Rust)

Crates.io Documentation License: MIT

A high-performance Vietnamese input method engine (IME) core written in Rust, ported from bamboo-core (Go).

Features

  • Telex, VNI, VIQR input methods with custom input method support
  • Hybrid engine: Rule-based transformations + Lazy JIT DFA caching
  • Zero heap allocation in core processing path (stack-allocated buffers)
  • O(1) backspace via snapshot stack
  • O(N) single-pass spelling validation
  • FFI for C/C++ integration and WASM bindings

Installation

[dependencies]
bamboo-core = "0.3.8"

Quick Start

use bamboo_core::{Engine, Mode, InputMethod};

let mut engine = Engine::new(InputMethod::telex());

let word = engine.process("tieengs", Mode::Vietnamese);
assert_eq!(word, "tiếng");

engine.reset();
let word2 = engine.process("vieetj", Mode::Vietnamese);
assert_eq!(word2, "việt");

Incremental Processing

Process keystrokes one at a time for IME integration:

use bamboo_core::{Engine, Mode, InputMethod};

let mut engine = Engine::new(InputMethod::telex());

engine.process_key('t', Mode::Vietnamese);
engine.process_key('i', Mode::Vietnamese);
engine.process_key('e', Mode::Vietnamese);
engine.process_key('e', Mode::Vietnamese);
engine.process_key('n', Mode::Vietnamese);
engine.process_key('g', Mode::Vietnamese);
engine.process_key('s', Mode::Vietnamese);
assert_eq!(engine.output(), "tiếng");

Delta Updates

For efficient text editor integration, use process_key_delta to get only the diff:

use bamboo_core::{Engine, Mode, InputMethod};

let mut engine = Engine::new(InputMethod::telex());

let (backspaces, _, inserted) = engine.process_key_delta('a', Mode::Vietnamese);
// backspaces = 0, inserted = "a"

let (backspaces, _, inserted) = engine.process_key_delta('s', Mode::Vietnamese);
// backspaces = 1, inserted = "á"  (replaces "a" with "á")

Backspace

use bamboo_core::{Engine, Mode, InputMethod};

let mut engine = Engine::new(InputMethod::telex());
engine.process_str("chuyeenr", Mode::Vietnamese);
assert_eq!(engine.output(), "chuyển");

engine.remove_last_char(true);
assert_eq!(engine.output(), "chuyên");

Output Customization

use bamboo_core::{Engine, Mode, InputMethod, OutputOptions};

let mut engine = Engine::new(InputMethod::telex());
engine.process_str("Trangws", Mode::Vietnamese);

// Toneless
assert_eq!(engine.get_processed_str(OutputOptions::TONE_LESS), "Trăng");

// Full text (committed + active)
assert_eq!(engine.get_processed_str(OutputOptions::FULL_TEXT), "Trăng");

Credits

  • Rust Port & Optimization: Dao Trong Nguyen (@nguyen10t2)
  • Original Author (Go): Lam (@lamtq)
  • Technical Consultant: Mai Tan Phat (@phatMT97) - Author of VKey

License

MIT. See LICENSE.