Skip to content

Rust reference

hpl-cjk-text is a small Rust library with one set of text rules for two users: the game, which links it statically through a C interface, and the Traditional Chinese translation tooling, which uses it as a Python module.

Open the Rust reference

Module What it holds
rules Where a line may break: CJK characters, no-line-start and no-line-end punctuation.
decode UTF-8 to 16-bit text, with characters beyond U+FFFF replaced and counted.
breakspace Spaces at every break, for the original game's word wrap.
ffi The C interface the game calls (hpl_cjk_text.h).

Rules of the boundary

  • No panic crosses into C++. The decoder catches a panic at the boundary and returns an error code; the other exported functions cannot panic.
  • Fixed-width types only. Exported structs and parameters use u8, u16, u32, i32 and pointers; a test checks their size and alignment.
  • Strings are borrowed. The caller passes a pointer and a length; Rust never keeps them.
  • The header is generated by cbindgen and committed; a test fails if it is out of date.

Build it locally with pixi run -e docs docs-api; the pages land in build/docs-api/rust. Run its tests with pixi run test-rust.