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!