Choose your own adventure: Run interpreted for rapid development or transpile to JavaScript for the entire npm ecosystem
fn greet(name: string) -> string {
format!("Hello, {}!", name)
}
fn main() {
let message = greet("World");
println(message);
}
function greet(name) {
return `Hello, ${name}!`;
}
function main() {
const message = greet("World");
console.log(message);
}
main();
Husk adapts to your workflow with two powerful execution modes
Perfect for rapid prototyping and learning
# Run directly - no setup needed!
husk run script.husk
# Or use the REPL
husk repl
> let x = 42
> println(x)
Tap into the entire JavaScript ecosystem
# Build your project
husk build
# Use with npm packages
npm install express
node dist/app.js
When you transpile to JavaScript, you get access to the entire npm ecosystem
Write scripts with Rust's clean, expressive syntax without the complexity of memory management
Rust's elegant syntax with JavaScript's ecosystem - use 1M+ npm packages while writing clean, type-safe code
Static typing with inference catches errors early while keeping your code concise and readable
enum Result {
Ok(int),
Err(string),
}
fn divide(a: int, b: int) -> Result {
if b == 0 {
Result::Err("Division by zero")
} else {
Result::Ok(a / b)
}
}
fn main() {
match divide(10, 2) {
Result::Ok(value) => println(format!("Result: {}", value)),
Result::Err(msg) => println(format!("Error: {}", msg)),
}
}
async fn fetchUser(id: int) -> Result<string, string> {
let response = fetch(format!("/api/users/{}", id)).await?;
let user = response.json().await?;
Ok(user.name)
}
async fn main() {
match fetchUser(123).await {
Ok(name) => println(format!("User: {}", name)),
Err(error) => println(format!("Failed: {}", error)),
}
}
// In utils.husk
pub fn log(message: string) {
println(format!("[LOG] {}", message));
}
// In main.husk
use local::utils::log;
fn main() {
log("Application started");
let numbers = [1, 2, 3, 4, 5];
for n in numbers {
log(format!("Processing: {}", n));
}
}
fn main() {
// Numeric conversions
let i = 42;
let f = i as float; // 42.0
// String parsing
let input = "123";
let num = input as int;
let doubled = num * 2;
println(format!("{} * 2 = {}", input, doubled));
// To string conversion
let result = doubled as string;
println(format!("Result: {}", result));
}
cargo install husk-lang
Requires Rust and Cargo. Install Rust
// hello.husk
fn main() {
println("Hello, Husk!");
}
husk run hello.husk
husk compile hello.husk | node