Rust for TypeScript Developers

July 26, 2025
#rust #typescript #systems programming

If you’re a frontend dev exploring Rust, you’ll love its emphasis on type safety, performance, and tooling.


🀝 Similarities

  • Strong static typing
  • Good tooling (e.g. Cargo = npm)
  • Expressive enums and pattern matching

🚧 Differences

  • Ownership model
  • No garbage collection
  • Compilation times (slower, but worth it)

✨ Hello World in Rust

fn main() {
    println!("Hello, TypeScript dev!");
}

πŸ“¦ Project Setup

cargo new hello-rust
cd hello-rust
cargo run

🧠 Borrowing vs. Ownership

fn greet(name: &str) {
    println!("Hello, {}", name);
}

You pass by reference using &str, not by value. Memory safety is enforced at compile time.


πŸ§ͺ Enums vs. Discriminated Unions

Rust:

enum Role {
    Admin,
    User,
    Guest,
}

TypeScript:

type Role = "Admin" | "User" | "Guest";

πŸ“š Error Handling

Rust uses Result<T, E> instead of exceptions:

fn divide(a: f64, b: f64) -> Result<f64, String> {
    if b == 0.0 {
        Err("Cannot divide by zero".into())
    } else {
        Ok(a / b)
    }
}

πŸ“Œ Conclusion

Rust has a steep learning curve, but pays off long-term.

If TypeScript is your safety net, Rust is your force field.


πŸ“˜ Learning Resources

My funny logo

0xws

Welcome !

πŸ‘‹ I’m ws (/vaΙͺs/), a DevSecOps engineer. This site is the place to gather my projects and thoughts on everything I like. From IT to anything related to cars and / or electronics.

I’m mostly working with Typescript, Python, Rust and Zig as daily drivers. These help me to perform my tasks in full-stack web development, system development, gamedev and plenty of other tasks.

On the infrastructure side, I’m mostly using Terraform/OpenTofu, K8s and NixOS.





HackTheBox Badge TryHackMe Badge Contact Me

πŸ™‹ Father of useless web apps. I like programming, cybersecurity and electronics.

πŸ§‘β€πŸ’» Aiming at becoming a Cloud security architect. I work with Typescript, Python and Rust.

Otherwise, I like race cars. β˜•

PGP: DDF4 D46C DAAA 62C0 D71B 24EE 84E0 D9E9 1805 69EA