| Crates.io | ruchy-wasm |
| lib.rs | ruchy-wasm |
| version | 4.0.1 |
| created_at | 2025-10-21 20:48:17.919004+00 |
| updated_at | 2026-01-12 22:15:40.248332+00 |
| description | WebAssembly bindings for Ruchy - compile Ruchy to Rust in the browser |
| homepage | |
| repository | https://github.com/paiml/ruchy |
| max_upload_size | |
| id | 1894423 |
| size | 193,766 |
WebAssembly bindings for the Ruchy programming language.
npm install ruchy-wasm
# Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build the WASM package
wasm-pack build --target web
# For bundler environments (webpack, vite, etc.)
wasm-pack build --target bundler
import init, { RuchyCompiler } from 'ruchy-wasm';
// Initialize the WASM module
await init();
// Create a compiler instance
const compiler = new RuchyCompiler();
// Compile Ruchy to Rust
const ruchyCode = `
struct Person {
name: &str,
age: i32
}
fn main() {
let alice = Person { name: "Alice", age: 30 }
println(alice.name)
}
`;
try {
const rustCode = compiler.compile(ruchyCode);
console.log(rustCode);
} catch (error) {
console.error('Compilation failed:', error);
}
import init, { RuchyCompiler } from 'ruchy-wasm';
async function compileCode(source) {
await init();
const compiler = new RuchyCompiler();
return compiler.compile(source);
}
import { RuchyCompiler } from 'ruchy-wasm';
const compiler = new RuchyCompiler();
// Validate syntax
const isValid = compiler.validate('let x = 42');
console.log('Valid syntax:', isValid); // true
const isInvalid = compiler.validate('let x = ');
console.log('Valid syntax:', isInvalid); // false
import { RuchyCompiler } from 'ruchy-wasm';
const compiler = new RuchyCompiler();
// Get AST as JSON
const ast = compiler.parse_to_json('fn add(a, b) { a + b }');
console.log(JSON.parse(ast));
RuchyCompilerconst compiler = new RuchyCompiler();
Creates a new Ruchy compiler instance.
compile(source: string): stringCompiles Ruchy source code to Rust.
source - Ruchy source code as a stringvalidate(source: string): booleanValidates Ruchy syntax without compilation.
source - Ruchy source code to validatetrue if syntax is valid, false otherwiseparse_to_json(source: string): stringParses Ruchy code and returns AST as JSON.
source - Ruchy source code to parseversion: stringReturns the Ruchy compiler version.
<!DOCTYPE html>
<html>
<head>
<title>Ruchy Playground</title>
</head>
<body>
<h1>Ruchy to Rust Compiler</h1>
<textarea id="input" rows="10" cols="80">
fn fibonacci(n) {
if n <= 1 {
n
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}
</textarea>
<button id="compile">Compile</button>
<pre id="output"></pre>
<script type="module">
import init, { RuchyCompiler } from './pkg/ruchy_wasm.js';
await init();
const compiler = new RuchyCompiler();
document.getElementById('compile').addEventListener('click', () => {
const source = document.getElementById('input').value;
try {
const rust = compiler.compile(source);
document.getElementById('output').textContent = rust;
} catch (error) {
document.getElementById('output').textContent = `Error: ${error}`;
}
});
</script>
</body>
</html>
import { RuchyCompiler } from 'ruchy-wasm';
const compiler = new RuchyCompiler();
const editor = document.getElementById('code-editor');
editor.addEventListener('input', () => {
const isValid = compiler.validate(editor.value);
editor.classList.toggle('error', !isValid);
});
Perfect for embedding in documentation sites like the Ruchy Book:
// In your documentation build system
import { RuchyCompiler } from 'ruchy-wasm';
const compiler = new RuchyCompiler();
// Add "Try it" buttons to code blocks
document.querySelectorAll('code.language-ruchy').forEach(block => {
const button = document.createElement('button');
button.textContent = 'Compile';
button.onclick = () => {
try {
const rust = compiler.compile(block.textContent);
showResult(rust);
} catch (e) {
showError(e);
}
};
block.appendChild(button);
});
The WASM binary is optimized for size:
Licensed under: