Expand description
§Bamboo Core
High-performance Vietnamese input method engine (IME) core written in Rust. Ported from bamboo-core (Go).
Supports Telex, VNI, VIQR input methods with custom rule support.
§API Overview
| API | Use case | Description |
|---|---|---|
Engine::process_key | IME integration (recommended) | Process one keystroke, update internal state |
Engine::process_key_delta | Text editor integration | Like process_key, returns (backspaces, inserted) diff |
Engine::process | Convenience | Process a full string, return output |
Engine::output | Read state | Get current composing word as String |
Engine::remove_last_char | Backspace | Undo last keystroke (O(1) via snapshot stack) |
Engine::commit | Confirm word | Finalize composing word into committed text |
Engine::reset | New session | Clear all state |
§Quick Start — IME Integration
Feed keystrokes one at a time with Engine::process_key:
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");For text editors, use Engine::process_key_delta to get a 3-way diff
(keep prefix + delete suffix + insert new):
use bamboo_core::{Engine, Mode, InputMethod};
let mut engine = Engine::new(InputMethod::telex());
let (bs, _, ins) = engine.process_key_delta('a', Mode::Vietnamese);
assert_eq!(bs, 0);
assert_eq!(ins, "a");
let (bs, _, ins) = engine.process_key_delta('s', Mode::Vietnamese);
// previous = "a", new = "á"
// keep prefix = 0 chars, delete = 1 ("a"), insert = "á"
assert_eq!(bs, 1);
assert_eq!(ins, "á");§Convenience API
Engine::process processes a full string in one call — useful for testing
or batch processing:
use bamboo_core::{Engine, Mode, InputMethod};
let mut engine = Engine::new(InputMethod::telex());
assert_eq!(engine.process("tieengs", Mode::Vietnamese), "tiếng");
engine.reset();
assert_eq!(engine.process("vieetj", Mode::Vietnamese), "việt");§Backspace
Engine::remove_last_char undoes the last keystroke in O(1) time
(snapshot stack, zero heap allocation):
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 OutputOptions to transform the output:
use bamboo_core::{Engine, Mode, InputMethod, OutputOptions};
let mut engine = Engine::new(InputMethod::telex());
engine.process_str("Trangws", Mode::Vietnamese);
assert_eq!(engine.get_processed_str(OutputOptions::TONE_LESS), "Trăng");Modules§
- advanced
- Advanced types for low-level interaction with the engine.
- ffi
- C-Compatible FFI Layer for Bamboo Core.
- wasm
- WebAssembly (WASM) bindings for Bamboo Core.
Structs§
- Config
- Configuration options for the Bamboo engine.
- Engine
- The main stateful processor of the Vietnamese Input Method Engine.
- Input
Method - A collection of rules defining how keys transform text.
- Output
Options - Customization options for the flattened string output.
- Transformation
- Represents a single keypress or a transformation derived from it (e.g., adding a mark or tone).
- Transformation
Stack - A stack-allocated buffer for transformations to avoid heap allocations in the hot path.
Enums§
- Mode
- Represents the processing mode of the engine.