Are We Frontend Yet?

Today’s Issue: FalKore’s Database Rewrite to Rust, Memory Ordering, and Biome’s First Birthday Anniversary 🎂

Rustaceans Editors
Rustaceans
6 min readSep 22, 2024

--

Ferris the crab mascot — Image courtesy of tweedegolf

If this email was forwarded for you, you can Subscribe here.

Hello, Rustaceans!

Welcome to another edition of the Rust Bytes newsletter. In this issue, we’ll discuss Rust’s readiness for Frontend web apps, share a useful Rust tip, spotlight an amazing Rust project, and share some incredible links of the week.

Welcome to issue 40.

THE MAIN THING

Are We Frontend Yet?

Rust is gaining momentum in the web development space lately and thanks to WebAssembly (WASM) for fueling this adoption. WASM makes it possible to run Rust code on the web, and allows integration with modern frontend tools like Node, and JavaScript/TypeScript.

It’s no doubt that JavaScript is supreme in the frontend space and especially on the web. But for applications demanding exceptional performance with bulletproof memory safety, Rust offers a compelling alternative. With WebAssembly, its is possible to integrate with modern frontend tooling.

The Rust for frontend tooling space is rapidly growing, with exciting new tools emerging regularly. Coupled with the vibrant Rust community fostering the development of such useful tools specifically designed for building web applications.

Here are some of the most promising options:

  • Leptos — A full-stack, isomorphic Rust web framework that leverages fine-grained reactivity to build declarative user interfaces.
  • Dioxus — A portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.
  • Iced — A cross-platform GUI library heavily inspired by Elm.
  • Sauron — A versatile web framework and library for building client-side and/or server-side web applications.
  • Sycamore — A library for building reactive web apps in Rust and WebAssembly.
  • Yew — A framework for creating reliable and efficient web applications.
  • Ratatui — A Rust crate for building terminal and networking user interfaces.

Rust’s potential for frontend development is slowly growing, and its ecosystem is still maturing. While this is still the case, on the contrary, for rapid prototyping and serious development cycles, JavaScript is still in a much better position with great tools, linters, and readily available resources that makes it a more practical choice.

A hybrid approach might be the sweet spot for many developers. Leveraging the power of Rust on the backend with frameworks like Actix-web or Axum, to ensure fast, memory safe, and secure server-side operations. Meanwhile, JavaScript can handle the frontend, allowing for rapid iteration and taking advantage of its amazing community and mature ecosystem.

Rust’s Frontend Potential: Ready, But Not Quite There Yet

Some companies i.e Pink Knowledge among other few companies, uses Rust for its full-stack apps. However, widespread frontend adoption isn’t quite there yet. Many more companies have disclosed using Rust on the frontend for their internal tooling, but it hasn’t become the norm across the entire frontend space.

I would love to see a future where Rust is used to augment other areas of the Frontend and not as a drop in replacement for JavaScript. Rust in conjunction with WASM would be great in performance intensive apps where reliability and safety might be of the highest concern.

Rust is still on its long way to becoming a viable frontend option, but JavaScript’s maturity in terms of tooling, resources, and established practices makes it a more practical choice for rapid development today.

RUST TIP

Zero-cost Abstractions with PhantomData for Marker Types

When dealing with advanced ownership patterns or marker traits, you might encounter situations where a type parameter needs to exist without actually being used at runtime.

Rust provides PhantomData for this purpose, and while it may seem esoteric, it can be incredibly useful for enforcing lifetimes or type constraints at compile-time without incurring any runtime cost.

Example: Enforcing Lifetimes Without Storing References

use std::marker::PhantomData;

struct MyStruct<'a, T> {
value: i32,
_marker: PhantomData<&'a T>, // PhantomData to tie `T` to lifetime 'a
}

impl<'a, T> MyStruct<'a, T> {
fn new(value: i32) -> Self {
MyStruct {
value,
_marker: PhantomData, // PhantomData is a zero-sized type
}
}

fn get_value(&self) -> i32 {
self.value
}
}

fn main() {
let s: MyStruct<'_, u8> = MyStruct::new(42); // 'u8' is purely compile-time
println!("{}", s.get_value()); // Output: 42
}

Play with the code on Rust Playground.

What’s Happening:

  • PhantomData<&'a T> creates a phantom reference, enforcing the lifetime 'a without storing an actual reference to T. This is useful when the structure's internal logic depends on lifetimes or type information that isn't directly used at runtime.
  • The key benefit here is that PhantomData allows us to specify ownership and lifetimes at compile-time, making the code more robust, while incurring zero runtime overhead since PhantomData is a zero-sized type.

Why It Matters:

This technique can be especially useful when writing advanced abstractions in Rust such as iterators, smart pointers, or custom collections. It ensures type safety and ownership semantics without impacting performance, a core advantage of Rust’s zero-cost abstractions.

PROJECT SPOTLIGHT 💡

Russh

Russh is a low-level Tokio SSH2 client and server implementation that’s packed with amazing features and high performance.

If you want to build secure, blazing-fast SSH connections with the power of asynchronous Rust? Then russh might be the crate you have been waiting for.

Here’s a taste of what awaits:

  • More panic safety (because who needs crashes when you’re building critical infrastructure?) ️
  • Async everywhere (because waiting is for slowpokes) ⚡️
  • Abundance of ciphers and key exchanges (enough to make Edward Snowden jealous)
  • Support for all the cool stuff: local/remote port forwarding, UNIX socket forwarding, OpenSSH certificates (client-only, for now )
  • OpenSSH keepalive and agent forwarding (because even ninjas need a break sometimes)

But wait, there’s more! We’re talking about:

  • Dependency updates (keeping your codebase fresh and secure)
  • A vibrant community of awesome contributors ready to lend a hand (Russh is not just about the code, its about the people too!)

Russh is open-source on GitHub.

AWESOME LINKS OF THE WEEK 🔗

  1. FalKoreDb’s team has announced plans to rewrite the database in Rust. Learn why they’re making this exciting migration. Link.
  2. Intel open-sourced simulator-bindings, a Rust binding, and essential tools for the Intel® Simics® Simulator.
  3. Linus Torvalds (OG of Linux), gave a keynote at the Linux Foundation and, surprise surprise, he addressed the ongoing Rust vs. C debate. Check it out!
  4. Evan Schwartz’s article on Understanding Memory Ordering in Rust is a must-read for anyone who wants to get their head around Rust’s memory model.
  5. Loco.rs v0.9.0 got released, and it’s walking on sunshine! ☀️ Amazing features, a brand new website, and docs so good you’ll forget Stack Overflow ever existed.
  6. Adam Mcdaniel released Dune — A shell designed for powerful scripting. Think of it as an unholy combination of bash and Lisp.
  7. Biome’s first birthday bash was a blast! 🎂 Version 1.9 is the gift that keeps on linting.
  8. Paweł Urbanek authored How I’ve built an unprofitable MEV Bot in Rust.
  9. Marvin released Fjall v2.0: the ultimate key-value storage engine for those who like their Rust a little… forbidden.
  10. Eddie Billoir released RootAsRole v3.0.0: the sudo/su upgrade that’ll make your sysadmin life a whole lot less stressful (and a whole lot more secure).

In Other news:

  • Vulnerable C++? Not anymore! Sean Baxter and Christian Mazakas have released the ‘Safe C++ Extensions’ proposal, turning C++ from a ticking time bomb into a safety net.

Do you have a Rust challenge/Tip you’d like to share with fellow Rustaceans? We’d be more than happy to feature them in a future issue, with full credit given to you. Submit your challenges or tips to us via email rustaceanseditors@gmail.com.

BEFORE YOU GO 👋

You’re Rust Bytes biggest fans, and we love to see it. Here are a few ways you can help us spread the word:

That’s all for now, Rustaceans. Can’t wait to see you in the next one.

John & Elley.

--

--