[ros-users] [Discourse.ros.org] [Next Generation ROS] Announcing Rust bindings for ROS2

Esteve ros.discourse at gmail.com
Thu Apr 19 08:20:38 UTC 2018



I'm far from being a Rust expert, so take my advise with a grain of salt.

I've found Rust to be a more modern (perhaps better) version of what C++ would be if it were designed today. The tooling is much better (actually, the tooling in C++ is non-existent, so that's easy to beat): things like a proper package manager (Cargo) and an official repository of packages (crates.io) make the Rust ecosystem much easier to start with and contribute to.

The language itself feels better designed as well. Concurrency in Rust is much more pleasant: among other things, variables are immutable by default and values are moved instead of assigned, and thanks to that, the compiler will tell you before compiling your program whether it's valid or not, preventing most data races (you can still deadlock a Rust program, though https://doc.rust-lang.org/beta/nomicon/races.html). Rust doesn't have a runtime, so when you compile a program it'll already have all the dependencies, so crosscompiling for embedded devices becomes trivial (or even crosscompiling Rust for WASM!). You can also compile a Rust program without Rust's standard library, and thanks to that, you can have Rust programs running on a microcontroller.

And that's only a few things that are directly applicable to robotics. But there are many other advantages in general. For example, template metaprogramming in C++ is difficult since the language does not yet support concepts (try debugging an ill-formed template), whereas Rust has traits (https://doc.rust-lang.org/book/second-edition/ch10-02-traits.html) that will check that a template implements a given behavior before being instantiated. Rust is also very is to embed, you can write your library in Rust and expose a C API. For example MesaLink (https://github.com/mesalock-linux/mesalink) uses the Rust rtls and sct cryptographic libraries and exposes a OpenSSL-compatible C API that can be used by C and C++ programs as a replacement for OpenSSL, while having all the advantages of Rust.  Unlike Go, Rust doesn't have a garbage collector, so it's closer to C and C++ than to higher-level languages like Java or Python.

That being said, there are a few things in Rust that need to be properly stabilized (e.g. it doesn't have a defined memory model, it just inherits whatever model LLVM has https://github.com/rust-lang/rfcs/issues/1447). In any case, I think Rust has a lot of potential and IMHO it's on the right track to become a serious alternative to C and C++.

BTW, if you want to try out Rust on ROS1, check out Adnan Ademovic's rosrust https://github.com/adnanademovic/rosrust It might help you get a better idea of what's possible with Rust while not having to learn ROS2.





---
[Visit Topic](https://discourse.ros.org/t/announcing-rust-bindings-for-ros2/3870/4) or reply to this email to respond.




More information about the ros-users mailing list