Short answer
Rust doesn’t need a “Numba for Rust” to make Rust code fast—the language is AOT-compiled to native code by default. What people usually want, though, is one of these two things:
Get a super-simple, “annotate this function and it’s magically faster” experience reminiscent of @numba.jit—but for Rust.
(2) isn’t really necessary in Rust, because the compiler already turns plain loops into very fast machine code. So the ecosystem focuses on (1): embedding a JIT engine you can drive from Rust.
Below are the main options, roughly ordered from “highest level & most batteries included” to “low level but maximum control”.
Wasmtime / Wasmer (WebAssembly JIT)
• Crates: wasmtime, wasmer
• Idea: Compile untrusted or sandboxed code written in any language that can target WebAssembly (Rust, C, AssemblyScript, Go, …) and run it in-process at near-native speed.
• Pros: Secure sandbox, fast compile times (Cranelift), mature embedding API, easy cross-platform.
• Cons: You’re dealing with WebAssembly, not raw native ABIs.
Cranelift (direct native JIT)
• Crates: cranelift, cranelift-module, cranelift-jit
• What it is: A modern code generator (used inside Wasmtime) that you can embed directly.
• You build Cranelift IR, ask it to JIT, then get back a function pointer you can unsafe { std::mem::transmute } into a typed fn.
• Pros: Faster JIT than LLVM, pure-Rust, small dependency footprint.
• Cons: Lower-level than Numba; you write IR or use a frontend like cranelift-codegen. No automatic “turn my Rust AST into Cranelift” yet.
LLVM-based JIT with Inkwell / LLVM-sys
• Crates: inkwell (safe wrapper), or go lower level with llvm-sys.
• This is closest to what Numba itself does internally (Numba → LLVM IR → ORC JIT).
• Pros: Mature optimizer, you can emit very high-quality code, lots of passes available.
• Cons: Bigger build, slower compile-time than Cranelift, API is C++-centric (hence thin wrappers).
• Minimal example (Inkwell, x86-64):
rust
use inkwell::{context::Context, OptimizationLevel};
fn main() {
let cx = Context::create();
let module = cx.create_module("demo");
let builder = cx.create_builder();
let f32_type = cx.f32_type();
let fn_type = f32_type.fn_type(&[f32_type.into()], false);
let function = module.add_function("square", fn_type, None);
let block = cx.append_basic_block(function, "entry");
builder.position_at_end(block);
let x = function.get_first_param().unwrap().into_float_value();
let result = builder.build_float_mul(x, x, "mul");
builder.build_return(Some(&result));
let execution_engine = module
.create_jit_execution_engine(OptimizationLevel::Aggressive)
.unwrap();
unsafe {
let square: extern "C" fn(f32) -> f32 =
std::mem::transmute(execution_engine.get_function_address("square").unwrap());
println!("square(3.0) = {}", square(3.0)); // 9
}
}
dynasm / capstone + mmap (hand-rolled assembly)
• Crates: dynasm, dynasmrt let you write machine code inline in Rust syntax and execute it.
• Pros: Zero dependencies, maximal control, extremely small & fast.
• Cons: You’re basically hand-coding assembly—fun for a VM backend or a JIT hot loop, but not “Numba easy”.
hot-reloading shared libraries (no real JIT)
• Crates: libloading, hot-lib-reloader.
• Technique: Compile a plugin .so/.dll on the side (still with rustc), swap it in-process while the program runs.
• Works great if you can tolerate the compile latency and want the illusion of JIT but with full Rust semantics.
Q. I just want a fast numerical kernel in Rust. Do I need any of this?
A. Probably not. Write the inner loop in plain Rust, turn on --release, maybe add rayon for parallelism and packed_simd/std::simd for vectorization. The Rust compiler + LLVM will produce code that’s on par with C/C++. Numba exists mainly to rescue Python from the interpreter—Rust starts native.
Q. Can I expose an “annotate with #[jit]” attribute for Rust functions anyway?
A. You could build a procedural macro that:
• Generates Cranelift/LLVM IR for the function body at runtime,
• Caches it, and
• Calls the generated function pointer.
Prototype crates like jit-derive have toy versions of this idea, but nothing production-ready yet. Most Rust devs simply don’t need it.
Q. I have users writing formulas/plugins—what should I embed?
• If you need sandboxing: WebAssembly via Wasmtime.
• If you need peak speed and trust the code: Cranelift or LLVM JIT.
• If you need a language frontend: Combine one of the above with pest/nom to parse your DSL, then spit out IR.
Bottom line
The Rust ecosystem offers multiple JIT engines (Cranelift, LLVM via Inkwell, Wasmtime) that you can embed in your application. Though there isn’t a one-liner decorator like @numba.jit, you usually don’t need it: Rust itself is already compiled and fast. Choose a JIT mainly when you want to execute dynamic or user-supplied code on the fly.