RUST → HAXE
Native Rust bindings
for Haxe
Write your library once in Rust. hxn generates the Haxe classes and native glue for HashLink, Ash and hxcpp — natively and on wasm.
Install the CLI
Latest releasecurl -fsSL https://raw.githubusercontent.com/hx-n/hxn/main/install.sh | bash
macOS & Linux · Windows via Git Bash
Release downloadsQUICK START
Your first native library.
A small Rust library, used from Haxe. Start with Rust, Haxe, and HashLink or hxcpp from git installed.
01 Create a library
hxn new creates a Rust crate and a Haxe program, ready to run.
hxn new greeter
cd greeter
02 Meet the two sides
These are the files the command creates. Mark the Rust interface and methods; hxn generates the Haxe class and native glue.
/// Greets people, and counts them.
#[hxn::interface]
pub struct Greeter {
greeting: String,
greeted: i32,
}
#[hxn::methods]
impl Greeter {
pub fn new(greeting: &str) -> Self {
Self {
greeting: greeting.to_owned(),
greeted: 0,
}
}
/// A greeting for `name`. Fails for an empty name.
pub fn greet(&mut self, name: &str) -> Result<String, &'static str> {
if name.is_empty() {
return Err("nobody to greet");
}
self.greeted += 1;
Ok(format!("{}, {name}!", self.greeting))
}
/// How many have been greeted.
pub fn greeted(&self) -> i32 {
self.greeted
}
}
class Main {
static function main() {
var greeter = new Greeter("Hello");
Sys.println(greeter.greet("Haxe"));
Sys.println(greeter.greet("Rust"));
Sys.println('${greeter.greeted()} greeted');
try {
greeter.greet("");
} catch (error:haxe.Exception) {
Sys.println('refused: ${error.message}');
}
greeter.close();
}
}
03 Run it
hxn builds the binding, compiles your Haxe program, and runs it on the target you choose. Both produce the same output.
hxn run hl
# Or use hxcpp:
hxn run cpp
Hello, Haxe!
Hello, Rust!
2 greeted
refused: nobody to greet
TUTORIALS
Build with hxn.
Small, runnable examples for the CLI and the APIs you use from Haxe.
Create, run and package
Use the CLI to build your first library, compare runtimes and share a haxelib.
02 / Build · Wasm · MobileBuild for other targets
Build native, wasm and mobile bindings, then add each platform to one haxelib package.
03 / Records · Collections · ErrorsPass data and handle errors
Use records, enums, sets and tuples from Haxe, then catch a typed Rust error.
04 / Callbacks · Bytes · OwnershipCall Haxe from Rust
Paint a picture with a Haxe function and let callback exceptions reach the caller.
05 / Futures · Streams · SignalsWork with asynchronous results
Await a future, read a stream and update a reactive value from Rust.