Skip to main content

Crate bamboo_core

Crate bamboo_core 

Source
Expand description

§Bamboo Core Rust

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

This crate provides the foundational logic for processing Vietnamese text, supporting various input methods like Telex, VNI, and VIQR. It is designed to be fast, memory-efficient (zero-allocation in core processing), and easy to integrate into UI applications or other text processing tools.

§Core Concepts

  • Engine: The main stateful processor. You feed it characters/strings, and it maintains the internal composition state to produce the correctly marked Vietnamese text.
  • InputMethod: Defines the rules for transformations (e.g., how “as” becomes “á”). Built-in methods include InputMethod::telex(), InputMethod::vni(), etc.
  • Mode: Determines if the engine should process characters as Vietnamese or treat them as plain English.
  • OutputOptions: A bitmask to customize the flattened string output (e.g., lowercase, toneless, etc.).

§Quick Start

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

// Create an engine with the standard Telex input method
let mut engine = Engine::new(InputMethod::telex());

// Process a string of keys
engine.process_str("tieengs", Mode::Vietnamese);
assert_eq!(engine.output(), "tiếng");

// Reset for a new word
engine.reset();
engine.process_str("vieetj", Mode::Vietnamese);
assert_eq!(engine.output(), "việt");

§Advanced Usage

§Customizing Output

You can use OutputOptions to transform the result on the fly:

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

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

// Get toneless version
let options = OutputOptions::TONE_LESS;
assert_eq!(engine.get_processed_str(options), "Trăng");

§Handling Backspaces

The engine supports removing the last transformation:

engine.process_str("chuyeenr", Mode::Vietnamese);
assert_eq!(engine.output(), "chuyển");

// remove_last_char removes the last 'appending' character and its marks
engine.remove_last_char(true);
assert_eq!(engine.output(), "chuyể");

Modules§

advanced
Advanced types for low-level interaction with the engine.
ffi
C-Compatible FFI Layer for Bamboo Core.
wasm

Structs§

Config
Engine
The main entry point for the Vietnamese Input Method Engine.
InputMethod
A collection of rules defining how keys transform text.
OutputOptions

Enums§

Mode