24 days of Rust - calling Rust from other languages

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

In this penultimate episode of the 24 days of Rust article series we will focus on using Rust code from other languages. Since Rust libraries can expose a C API and calling conventions, using them isn't very different from using regular C libraries. A lot of programming languages have some kind of an FFI mechanism, allowing them to use libraries written in other language(s). Let's see a few examples!

Czytaj dalej »
Napisane 23 grudnia 2014

FFI in Rust - writing bindings for libcpuid

A few days ago I needed to find my CPU name and clock frequency in a Rust program. One can parse /etc/cpuinfo or the output of lscpu, but I wanted to encapsulate this functionality in a library of sorts. Meanwhile, I stumbled upon libcpuid, which is a small C library that does exactly what I needed (although not by reading from the proc filesystem). That left me wondering how hard would it be to create a Rust wrapper for libcpuid. Turns out it's quite simple!

Czytaj dalej »
Napisane 20 września 2014