Marvels you can do with Rust: Case XAIN

By Joni Käki-Mäkelä, Senior Software DevelopersMar 10, 2021Read time 3 min
computer-rust-coding

Companies around the world –from startups to large corporations– are using Rust in production for fast, low-resource, cross-platform solutions. This article is a practical example of how you can Use Rust for Successful Projects.

XAIN, currently known as Xayn, is one of the companies we have worked with Rust. The Berlin-based start-up specialised in cybersecurity and distributed ledger technologies for the mobility sector. The company was known for collaborating with Porsche and becoming the first to apply blockchain technology to a vehicle. The objective of the project was the development of a domain specific language (DSL) and protocol for an attribute-based decentralised access control solution for IoT devices.

Defining the core of the project

The core of the project was a reference implementation of a compiler that processed the previously mentioned DSL, as well as validation and execution engine for the actual policies that were defined using the DSL. Additionally, a web-service that acted as a repository for the written access control policies, as well as handled the validation of the policies that were submitted to it, was created.

The ultimate goal was to create multiple types of repositories (e.g. plain old databases, files, third party integrations) to be used to store the policies. 

Wunderdog as a Rust expert

Wunderdog’s role in the project team was to act as a Rust language expert, while also working on the actual implementation. Rust enabled us to write code that ran both on embedded IoT devices and on plain old web servers while keeping the code mostly the same.

The only difference was that the IoT devices required the code to be compiled without Rusts’ standard library. In practice this meant using #![no_std] compatible code and crates, which was no problem at all. The biggest challenge was that the “petgraph”, graph library we used for managing the DSL syntax tree, did not have no_std support. This challenge was solved by forking the library and modifying it to meet the needs, while also providing a pull-request on Github for the authors about the changes. The web server part exposed a gRPC interface that used protocol buffers for data serialization. Implementing these features was pretty straight-forward as there were mature-enough libraries. For validating the policies that were submitted to it, the server used the very same library as ran on the embedded IoT devices. 

Working with Rust: What's it like?

In a nutshell, Rust’s tooling made development very easy. The Rust ecosystem has several libraries for handling pretty much any existing requirement. Rust features made working with data parsing and abstract syntax trees a breeze. 

Working with Rust kind of ruined the fun of other programming languages for Wunderdog's developer Joni: when the code compiles, barring any logic errors, you can be sure that your application works.

Rust has extremely powerful compile time checks for lots of things that normally require programmer's attention with languages such as Javascript, Java and C++. Some types of errors just don't exist in programs created with Rust. Additionally, even concurrent and parallel systems are easy to write with Rust since the compiler refuses to compile faulty code including data races and such.

Native code compilation is _FAST_ and applications require miniscule amounts of memory compared to apps running e.g. on JVM. All in all, this was an excellent project.


This article was written by Joni Käki-Mäkelä, who carried out the XAIN project. Joni works as a software developer in Wunderdog's Finnish office.