Rust Meets Dart With Release of rust_core 1.0.0
rust_core version 1.0.0 has been released.
According to the r/dartlang subreddit, rust_core is an implementation of Rust‘s core library in Dart.
By making adjustments to Rust’s features to align with Dart’s principles, the goal of the implementation is to create a seamless and natural integration between the two languages. This enables developers to use advanced tools that were once exclusive to Rust developers, allowing for a smooth transition between the languages.
The project goals state that “rust_core strives to bring reliability and performance in every feature. Every feature is robustly tested. Over 500 meaningful test suites and counting.”
Moreover “For Rust developers involved in programming with Dart, or Dart developers interested in idiomatic and safe programming, we have developed ‘rust_core,’ a package designed to implement Rust’s core library in Dart,” wrote Henry McMahon in a blog post last November.
The company behind the rust_core project is called Voyver, a startup in the AI and educational software space. McMahon is the primary maintainer on the team for rust_core.
“We primarily use Dart and Rust in our stack,” he told The New Stack. “A common API was identified as a missing piece to the primarily Rust developer team and codebase. rust_core solved that for us.”
McMahon, who is a lead software engineer at Voyver, said that with just Rust and Dart the Voyver team can accomplish everything they need to.
Indeed, Rust can go anywhere, he said.
“Rust is helping us develop our server architecture while being scalable, fast, and safe. On the client side, Rust is helping us bring AI models to users. We also have a few utilities that we use on both the client and server side (Dart ffi on the client side),” McMahon said. Meanwhile, “An internal CLI tool was also developed with Rust and successfully helps us manage our environments.”
However, “With Dart we can bring user experiences to life on multiple platforms (iOS, Android, Windows, and macOS for us) in one codebase, while being able to iterate quickly,” he noted. “Flutter is key to being able to accomplish this. Dart has also replaced most of our internal scripts and has shown to be a good alternative to Python or Bash.”
Moreover, Voyver benefits greatly from the development velocity from being able to only use two specialized languages, McMahon told The New Stack.
“Dart solves some issues of development for us and Rust the others,” he said. “Leaning into Rust’s type system with rust_core brings a common API to make our team that much more efficient and takes advantage of Rust’s maintainable development philosophy and mature core library.”
Rust Core Book
To support the 1.0.0 release, the rust_core project also released the Rust Core Book.
The Rust Core Book features an FAQ, which includes as the first question: Why Use Rust Core Even If I Don’t Know Rust?
In response, the FAQ reads: “From a language perspective we believe Dart is sadly lacking in a few areas, of which this package solves:
- Dart utilizes unchecked try/catch exceptions. Handling errors as values is preferred for maintainability, thus the
Result
type. - Dart has nullable types but you cannot do null or non-null-specific operations without a bunch of
if
statements.Option<T>
fixes this with no runtime cost and you can easily switch back and forth to nullable types since it is just a zero cost extension type ofT?
. - Dart is missing the functionality of Rust’s
?
operator, so we implemented it in Dart. - Dart is missing a built-in
Cell
type or equivalent (andOnceCell
/LazyCell
). - Dart’s
List
type is an array/vector union (it’s growable or non-growable). This is not viewable at the type layer, which may lead to runtime exceptions and encourages using growableList
s everywhere even when you do not need to, which is less performant. So we addedArr
(array). - Dart has no concept of a slice type, so allocating sub-lists is the only method, which is not that efficient. So we added
Slice<T>
. - Dart’s between isolate communication is by ports (
ReceivePort
/SendPort
), which is untyped and horrible, we standardized this with introducingchannel
for typed bi-directional isolate communication. - Dart’s iteration methods are lacking for
Iterable
andIterator
(there are none! justmoveNext()
andcurrent
), while Rust has an abundance of useful methods. So we introduced Rust’sIterator
.”
Meanwhile, Rust is being adopted more broadly in use cases where memory-safe programming is recommended.