Skip to main content

Crate bamboo_core

Crate bamboo_core 

Source
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

APIUse caseDescription
Engine::process_keyIME integration (recommended)Process one keystroke, update internal state
Engine::process_key_deltaText editor integrationLike process_key, returns (backspaces, inserted) diff
Engine::processConvenienceProcess a full string, return output
Engine::outputRead stateGet current composing word as String
Engine::remove_last_charBackspaceUndo last keystroke (O(1) via snapshot stack)
Engine::commitConfirm wordFinalize composing word into committed text
Engine::resetNew sessionClear 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.
InputMethod
A collection of rules defining how keys transform text.
OutputOptions
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).
TransformationStack
A stack-allocated buffer for transformations to avoid heap allocations in the hot path.

Enums§

Mode
Represents the processing mode of the engine.