Hello Rustacean! Welcome to another edition of the Rust Bytes newsletter. In this issue, we'll shine a spotlight on an amazing Rust project, present our spot-the-bug challenge, and share some incredible links of the week.
Welcome to Issue 16!
The Main Thing
Rise of Rolldown and Beyond
The JavaScript ecosystem thrives on a vast amount of tools, but a new trend is emerging: JavaScript tooling written in Rust. This shift raises the question: Is Rust the future of JavaScript tooling?
The Allure of Rust:
Rust offers several advantages for building high-performance tools:
Speed: Rust is blazingly fast, translating to faster builds and quicker development cycles for JavaScript projects.
Memory Safety: Rust's ownership system eliminates entire classes of memory-related errors common in JavaScript tooling written in languages like C++.
Concurrency: Rust excels at handling multiple tasks simultaneously, allowing for parallel processing during builds and optimizations.
Enter Rolldown:
Rolldown, a recently released Rust bundler, exemplifies this trend. It boasts a Rollup-compatible API, allowing seamless integration into existing JavaScript workflows. This highlights Rust's potential to not just replace, but enhance existing tooling ecosystems.
Beyond Rolldown:
Several other popular JavaScript tools are already written in Rust, including:
SWC: An extremely fast JavaScript/TypeScript compiler used by tools like Next.js and Parcel.
Deno: A secure runtime environment for JavaScript and TypeScript built with Rust.
Rome: A comprehensive toolchain encompassing bundling, linting, and testing, all powered by Rust.
Thought-provoking Insights:
Coexistence: Will Rust completely replace existing JavaScript tooling written in languages like Node.js? It's more likely that both paradigms will coexist, with Rust taking over performance-critical areas and JavaScript remaining strong for scripting needs.
Interoperability: Tools like Rolldown demonstrate the potential for seamless interoperability between Rust and JavaScript tooling. This could lead to a future where developers leverage the strengths of both languages.
Developer Experience: While Rust offers technical benefits, the learning curve for developers familiar with JavaScript can be steeper. How can the tooling ecosystem bridge this gap and make Rust adoption smoother?
The Future is Open:
The rise of Rust in JavaScript tooling is undeniable. While it's too early to declare it the sole future, Rust offers clear advantages in terms of performance and memory safety. As tools like Rolldown emerge, the future of JavaScript development likely involves a closer collaboration between these two languages, with each playing to its strengths. The path forward will depend on how the tooling ecosystem evolves and how well it addresses developer needs and preferences.
Rust Pun
Why is it called Rust?
That's what your machine will be by the time the compilation finishes.
Spot the Bug
Identify why the code fails to compile and suggest a way to fix it.
Share your solution in the comments below for a chance to be featured in our next newsletter!
Project Spotlight
Servo
Servo is a secure and modern web rendering engine built with Rust and designed for the future. Here's what makes Servo stand out:
Built for Security: Written entirely in Rust, Servo prioritizes memory safety, eliminating a major source of vulnerabilities found in traditional browser engines.
Parallel Power: Servo leverages Rust's concurrency features to render web content in parallel, aiming for a faster and smoother browsing experience.
Future-Proof Technology: Constantly exploring innovative rendering techniques and integrating with cutting-edge technologies like WebGPU, Servo helps shape the future of web graphics.
More than just an engine:
Standardization Champion: Servo actively contributes to web standard development by identifying issues and proposing improvements, benefitting the entire web ecosystem.
Rust Playground: Servo serves as a large-scale testbed for Rust, pushing the language's capabilities and informing its evolution.
Get Involved:
Servo is open-source on GitHub and welcoming contributions from developers.
Awesome links of the week
Rust v1.77.1 arrived quickly after v1.77.0. This minor release focuses on fixing a bug introduced in version 1.77.0 that caused debuginfo to be stripped from Windows builds by default. This is a minor release focused on fixing a regression, so there aren't any major new features.
Denys Séguret released codesort, a tool that tackles the tedious task of sorting specific code sections alphabetically, right within your IDE. No more messing with comments or spacing – codesort keeps your code clean and organized, boosting readability for you and your collaborators.
The team at Agriconnect wrote a guide on implementing Over-the-Air (OTA) firmware updates for ESP32 devices using Rust. Read more here.
Cliff L. Biffle shared a captivating tale of how seemingly benign features within Hubris, an OS designed for embedded systems, unexpectedly collaborated to breed a fatal bug. Read more on the story here.
Ben Ruijl authored an article titled “How I learned to stop worrying and love the global state,” discussing his experiences in overcoming challenges associated with managing global state within Symbolica (a blazing fast computer algebra system).
Hanno Braun released Fornjot v0.49.0, an early-stage b-rep CAD kernel written in Rust, packed with new features!
“Everything you need to know about testing in Rust" is an article guide by Joshua Mo that discusses essential concepts for writing tests in Rust.
Armin Ronacher reflects on tech debt in his recent article, “On Tech Debt: My Rust Library is now a CDO,” shedding light on the Rust ecosystem's approach to addressing this issue. He discusses the concept of collateralization, where integrating problematic dependencies into one's codebase can seemingly elevate their status from debt to asset.
Wedson Almeida Filho from Microsoft is pushing the Rust for Linux kernel development with two key contributions, an improved allocation APIs, and In-place Module Initialization. Read more about this here.
John Nunley wrote about “Why choose async/await over threads?”. He discusses the reasons why you might choose async/await over threads in Rust.
Spot The Bug: Solution
The Bug: Compiler error!
Solution:
The struct `UInt64Counter` is generic over the type parameter `Key` which is used as the HashMap key.
struct UInt64Counter<Key> {
count_by_key: HashMap<Key, u64>
}
The `add` method increments the counter for the provided key using the `entry` method of the `HashMap`.
fn add(&mut self, key: Key, delta: u64) {
*self.count_by_key.entry(key).or_default() += delta;
}
If we look at the `entry` method of the `HashMap`, it is defined with with a few generic type parameters and one of them is the parameter K, `K: Hash+Eq`. This parameter is the key of the HashMap.
impl<K, V, S> HashMap<K, V, S>
where
K: Eq + Hash,
S: BuildHasher,
{
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
map_entry(self.base.rustc_entry(key))
}
}
This constraint means that the `entry` method exists for the `HashMap` if the key implements `Eq` and `Hash` traits. Hence, the compiler gives the error: "the method `entry` exists for struct `HashMap<Key, u64>`, but its trait bounds were not satisfied"
To solve the compilation error, we must use the constraint Eq + Hash in the generic parameter of `UInt64Counter`.
struct UInt64Counter<Key: Eq + Hash> {
count_by_key: HashMap<Key, u64>,
}
impl<Key: Eq + Hash> UInt64Counter<Key> {
fn new() -> Self {
return UInt64Counter {
count_by_key: HashMap::new()
};
}
fn add(&mut self, key: Key, delta: u64) {
*self.count_by_key.entry(key).or_default() += delta;
}
}
Before You Go
To support the newsletter:
❤️ Recommend the newsletter to your friends: it really helps!
💸 Sponsor the newsletter
🤳 Check us out on our socials: X, Rustaceans Publication.
📨 Contact us through rustaceanseditors@gmail.com feedback is welcome
That's all for now, Rustaceans! Until next week, have a productive week ahead.