|Rust 1.39 Gets Async-Await|
|Written by Ian Elliot|
|Friday, 08 November 2019|
The latest version of Rust adds async-await for easy asynchronous programming and Microsoft thinks the language could be an alternative to C++.
While a lot of people want to talk about Go, it is Rust that is really offering something new and it deserves to be the hottest language that is around at the moment. That Rust isn't claiming the limelight is perhaps because we tend to see new as difficult and it is true that the learning curve for Rust is steeper.
It is often claimed that strong typing is the key to bug-free programming - well fewer bugs at least - but Rust's use of ownership really does cut down the bugs.
What you do is declare a function to be await-able using async:
async fn myFunction()
When you call an async function it doesn't do the computation. Instead it returns a Future which is the computation but in a suspended state. To start the computation all you have to do is use the .await operator:
let myFuture = myFunction();
In this sense Rust's Futures are lazy - they don't execute until you await them. It is claimed that async-await integrates well into the "borrowing" system, which is how Rust shares objects between owners.
With the adoption of the async-await approach to asynchronous programming, Rust again emphasizes the fact that it is trying to be a modern language. It may be a language that has a lot to do with Mozilla, but Microsoft seems to be keen to give it a fair trial after discovering that most of the bugs they have to deal with are due to memory allocation errors. You have to try quite hard in Rust to create this sort of error and hence it makes a good replacement for C++.
Adam Burch, Software Engineer, Hyper-V team writes:
"This blog describes part of the story of Rust adoption at Microsoft. Recently, I’ve been tasked with an experimental rewrite of a low-level system component of the Windows codebase (sorry, we can’t say which one yet). Instead of rewriting the code in C++, I was asked to use Rust, a memory-safe alternative. Though the project is not yet finished, I can say that my experience with Rust has been generally positive. It’s a good choice for those looking to avoid common mistakes that often lead to security vulnerabilities in C++ code bases."
The only real negatives mentioned are omissions:
"Given Rust’s relative youth, there are still some missing language features that would be very desirable for our development. Foremost of these are safe transmutation (safely cast “plain old data” types to and from raw bytes), safe support for C style unions, and fallible allocation (fail gracefully from allocation failure, rather than panic)."
There are also some shortcomings in the unit testing abilities of Rust's Cargo.
It will be interesting to see how Rust fares in the longer term as an alternative to C++ which is deeply entrenched at Microsoft as it is what most of Windows is written in.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Wednesday, 22 July 2020 )|