Rust & WebAssembly · Patterns
Feature-Flagging Native Accelerators
Making the WASM build optional, never required.
1 min readPublished Updated
- feature flags
- wasm
ts
export type CoreEngine = "wasm" | "ts";
export async function loadCore(enableWasm: boolean) {
if (!enableWasm) return { engine: "ts" as const };
try {
return { engine: "wasm" as const };
} catch {
return { engine: "ts" as const };
}
}A feature flag plus a safe fallback means the WASM build is always optional, never required.
The badge in the playground shows which engine computed the results: ts for the TypeScript fallback, wasm for the Rust build.
Rust AI playground