Rust wide web (2/5)
This is part 2 of 5 of our series "Why we love Rust". Check out the complete series here
All those languages… What made Rust pop out?
Having a language with procedural elements (like with C) that is statically typed, and that is memory safe without using a garbage collector is a new concept, that excites me the most. Manual memory management without any checks is really hard, most languages opt for a runtime garbage collector (incurring some runtime overhead). Meanwhile Rust has language semantics that allow it to check and bake memory management into your program at compile time using the borrow checker. Rust’s memory-safety is baked in the compiler with it’s borrow checker.
That’s cool and all, but I’m like… super productive in C++. I don’t have time to fight that “borrow checker” of yours.
Sure, but unfortunately most programmers are human and humans make mistakes. While you have concepts like RAII in languages like C++, which help you with memory management, the compiler doesn’t actually enforce it. The Rust compiler makes sure there is always only one owner of a resource and enforces responsibility for that resource. It is simply impossible to access already freed memory without the compiler yelling at you for it first. So all the time we are spending hunting those runtime memory-related issues is now spent actually working on the problem we are trying to solve.
Need an introduction to Rust?
Ruben did an introductory talk (dutch) about Rust back in 2016. The nice thing about it, is that the talk is still quite relevant, as many of the topics discussed still apply as of today. A lot of features he promises to be implemented somewhere in the future are now actually released, so if you speak Dutch, definitely check it out!
What is your most recent Rust project?
Currently I’m evaluating if Rocket is viable as one of Tweede golf’s standard web frameworks. Rocket’s ecosystem hasn’t reached full maturity yet, so there are still things we would have to write ourselves, but new, useful crates are released monthly. We’re almost at a point where most REST APIs are pretty viable to create in Rust, albeit with a somewhat high learning curve. In the future I expect this to only become easier.
Ruben’s takeaway
Rust learned from one of Node.js’s problems around package repositories. Crate versions on crates.io are permanent. A certain version cannot be deleted or overwritten, so you’ll be guaranteed that when you depend on a certain version of a crate, that version’s code will always be the same.
Will Rust become *the language of the web?*
That’s a tough one. Working with the web means handling a lot of string based or unstructured input, which doesn't work well when all you really have are strictly defined types. It's definitely manageable, but not as easy as slapping some strings together in Javascript or PHP. Also, because of the way ownership and callbacks work, it’s not a perfect language for UI programming (although it’s definitely not impossible when looking at games that are currently being made in Rust).
On the other hand, the small memory footprint, great error handling and features like async/await, make it perfect for certain web services. Let’s also not forget the amount of work being done around webassembly.
Rust is a well-structured, well-thought-out, well-planned language, so it’s definitely a language we should want on the web!
More by Ruben
A blog post about Instant data retrieval from large point clouds