3 unstable releases

0.2.1 Apr 14, 2024
0.2.0 Mar 23, 2024
0.1.0 Mar 18, 2024

#471 in Unix APIs

39 downloads per month

MIT license

8KB
62 lines

sysinfo dot h

A tiny <sys/sysinfo.h> wrapper in Rust

How?

Quick start:

use sysinfo_dot_h::try_collect;

let info = try_collect().unwrap();
dbg!(info.uptime); // uptime in seconds

or

use sysinfo_dot_h::collect;

let info = collect();
dbg!(info.uptime); // uptime in seconds

Why?

This makes it easier (and quicker) to port the following C code to rust:

#include <sys/sysinfo.h>
int main() {
    struct sysinfo *info;
    sysinfo(info);
}

The sysinfo crate was too slow for my use case (200 milliseconds) so I made my own.

Please note that unlike sysinfo, this crate only works on Linux, so if your application is cross platform it may not be favourable to use this crate.


lib.rs:

This crate uses raw FFI bindings to easily and quickly get and use the <sys/sysinfo.h> struct. Please read the README if you want to know more.

Internally, this crate calls unsafe {} because of FFI. You, the programmer, are ultimately responsible for any downtime in prod or similar

No runtime deps