Originally created by Mozilla, Rust is a fast, reliable, memory-efficient, extremely popular programming language designed for performance and safety.
In fact, it’s been voted the most loved programming language six years in a row in Stack Overflow surveys and is widely used at hyper-scale companies such as Facebook, Apple, Amazon, Microsoft, and Google for systems infrastructure, encryption and virtualization.
What is Rust?
Rust helps developers write fast software that’s memory-efficient. It’s a modern replacement for languages like C++ or C, focusing on code safety and concise syntax.
The language abstracts the developer from thinking about manual memory management. With Rust, developers have more control over memory allocation without it being as painful as C++.
“Rust uses a relatively unique memory management approach that incorporates the idea of memory ‘ownership’. Basically, Rust keeps track of who can read and write to memory. It knows when the program is using memory and immediately frees the memory once it is no longer needed. It enforces memory rules at compile time, making it virtually impossible to have runtime memory bugs. You do not need to keep track of your memory manually. The compiler takes care of it.” — Discord
On top of the companies mentioned above, Rust is also being used for popular open source libraries like:
“Rust has been a force multiplier for our team, and betting on Rust was one of our best decisions. More than performance, its ergonomics and focus on correctness has helped us tame sync’s complexity. We can encode complex invariants about our system in the type system and have the compiler check them for us.” — Dropbox
- Terser: Developers wanted to generate the smallest possible file sizes.
- Prettier: Developers wanted an opinionated code formatter that just worked.
- ESLint: Developers wanted to find issues with their code before deploying.
Millions of lines of code have been written, and even more bugs have been fixed to create the bedrock for shipping web applications of today.
SWC, created in 2017, is an extensible Rust-based platform for the next generation of fast developer tools. It’s used by tools like Next.js, Parcel, and Deno, as well as companies like Vercel, ByteDance, Tencent, Shopify and more.
SWC can be used for compilation, minification, bundling and more — and is designed to be extended. It’s something you can call to perform code transformations (either built-in or custom). Running those transformations happens through higher-level tools like Next.js.
“The Rust version probably could be made to work at an equivalent speed with enough effort. But at a high level, Go was much more enjoyable to work with. This is a side project and it has to be fun for me to work on it.” — Evan, creator of esbuild
Some argue Rust could perform better, but both could achieve Evan’s original goal of influencing the community:
“Even with just basic optimization, Rust was able to outperform the hyper hand-tuned Go version. This is a huge testament to how easy it is to write efficient programs with Rust compared to the deep dive we had to do with Go.” — Discord
Why rewrite everything, then?
“Making the necessary modifications to Babel to allow for it to be a reliable base for other tools would have required changes to absolutely everything. The architecture is bound to the initial design choices I made in 2014 when I was learning about parsers, ASTs, and compilers.” — Sebastian McKenzie
Rome is currently written in TypeScript and runs on Node.js. But they’re now working on rewriting in Rust using RSLint parser and their own visitor system for AST traversal.
Rust’s integration with Node.js is better than other low-level languages. napi-rs allows you to build precompiled Node.js add-ons with Rust. It provides an out-of-the-box solution for cross-compilation and publishing native binaries to NPM, without needing
You can build a Rust module that can be called directly from Node.js without needing to create a child process like esbuild.
Rust + WebAssembly
“WASM is definitely a lot faster than JS, but not quite native speed. In our tests, Parcel runs 10-20x slower when compiled to WASM than with native binaries.” — Devon Govett
While WASM isn’t the perfect solution yet, it can help developers create extremely fast web experiences. The Rust team is committed to a high-quality and cutting-edge WASM implementation.
For developers, this means you could have the performance advantages of Rust (versus Go) while still compiling for the web (using WASM).
Some early libraries and frameworks in this space:
Why Not Rust?
Rust has a steep learning curve. It’s a lower level of abstraction than what most web developers are used to. Once you’re on native code (through Rust, Go, Zig, or other low-level languages), the algorithms and data structures are more important than the language choice. It’s not a silver bullet.
“Rust makes you think about dimensions of your code that matter tremendously for systems programming. It makes you think about how memory is shared or copied. It makes you think about real but unlikely corner cases and make sure that they’re handled. It helps you write code that’s incredibly efficient in every possible way.” — Tom MacWright
Currently, it’s hard to find a Rust library or framework for your favorite services (things like working with authentication, databases, payments and more).
- Extensibility: SWC can be used as a Crate inside Next.js without having to fork the library or work around design constraints.
- Performance: We achieved ~3x faster Fast Refresh and ~5x faster builds in Next.js by switching to SWC with more room for optimization.
- WebAssembly: Rust’s support for WASM is essential for supporting all possible platforms and taking Next.js development everywhere.
- Community: The Rust community and ecosystem are amazing and only growing.
It’s not just Next.js adopting SWC, either:
“Parcel uses SWC like a library. Before we used Babel’s parser and custom transforms written in JS. Now, we use SWC’s parser and custom transforms in Rust. This includes a full scope hoisting implementation, dependency collection, and more. It’s similar in scope to how Deno built on top of SWC.” — Devon Govett
It’s the early days for Rust — a few important pieces are still being figured out:
- Bundling: One interesting area of development is, which is SWC’s replacement for webpack. It’s still under development but could be very promising.
- WebAssembly: As mentioned above, the prospect of writing Rust and compiling to WASM is enticing, but there’s still work to be done.
To get the best Rust developers to work for you, connect with InApps.
List of Keywords users find our article on Google
Let’s create the next big thing together!
Coming together is a beginning. Keeping together is progress. Working together is success.