Rust
JavaScript
Web Development
Performance
Programming
Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan
Rust is already inside your JavaScript toolchain. SWC (used by Next.js), Turbopack, Biome, Deno, and dozens of npm packages are written in Rust. Understanding it gives you a superpower.
| JS Tool | Rust Replacement | Speed Improvement |
|---|---|---|
| Babel | SWC | 20-70x faster |
| Webpack | Turbopack | 700x faster (HMR) |
| ESLint + Prettier | Biome | 25x faster |
| Node.js | Deno (partial) | 2-5x faster |
| npm | pnpm (partial) | 3x faster |
Next.js build times (large project):
With Babel: 180 seconds
With SWC: 12 seconds ← 15x faster!
Hot Module Reload:
Webpack: 1200ms
Turbopack: 8ms ← 150x faster!
rust// JavaScript:
// let name = "Farhan";
// const age = 25;
// Rust:
let name = "Farhan"; // immutable by default!
let mut age = 25; // mut = mutable
let score: f64 = 99.5; // explicit type
// No null/undefined — use Option
let email: Option<String> = Some("test@example.com".to_string());
let phone: Option<String> = None;
rust// JavaScript:
// function add(a, b) { return a + b; }
// Rust:
fn add(a: i32, b: i32) -> i32 {
a + b // no return keyword needed for last expression
}
// Closures (similar to arrow functions)
let multiply = |x: i32, y: i32| -> i32 { x * y };
rust// Rust uses Result<T, E> instead of exceptions
fn read_file(path: &str) -> Result<String, std::io::Error> {
std::fs::read_to_string(path)
}
// Usage with ? operator (like optional chaining for errors)
fn process() -> Result<(), Box<dyn std::error::Error>> {
let content = read_file("data.txt")?; // returns error if fails
println!("{}", content);
Ok(())
}
ruststruct User {
name: String,
age: u32,
active: bool,
}
impl User {
fn new(name: &str, age: u32) -> Self {
User {
name: name.to_string(),
age,
active: true,
}
}
fn greet(&self) -> String {
format!("Hi, I'm {} and I'm {} years old", self.name, self.age)
}
}
rustuse actix_web::{web, App, HttpServer, HttpResponse};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct User {
id: u32,
name: String,
}
async fn get_users() -> HttpResponse {
let users = vec![
User { id: 1, name: "Farhan".into() },
User { id: 2, name: "Alice".into() },
];
HttpResponse::Ok().json(users)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/users", web::get().to(get_users))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
| Benchmark | Node.js | Rust | Improvement |
|---|---|---|---|
| HTTP requests/sec | 45K | 180K | 4x |
| JSON serialization | 12ms | 0.8ms | 15x |
| File processing (1GB) | 8.5s | 1.2s | 7x |
| Memory usage | 120MB | 8MB | 15x |
| Cold start | 200ms | 5ms | 40x |
Yes, if you:
Rust won't replace JavaScript, but it's becoming the language that powers JavaScript. Learn it to level up.