This month in heim - August 2019
It’s been a month and a half since the heim public announcement,
so it’s about time to sum up the work done and make a roadmap for next development iteration.
As a quick reminder: heim
is the Rust cross-platform async library
for system information fetching — CPU, memory, disks, networks, you name it.
What’s new?
- You can fetch a system hostname now
- Added Linux, macOS and Windows-specific info about users
- Linux and macOS-specific info for network interfaces is available too
- A few bugs and memory leaks fixed
- Code is properly “async” now (see the runtimes section below)
- And some other small changes, which can be found at CHANGELOG.md
System processes
Querying system processes is now possible with the new heim::process
module:
let current = heim::process::current().await?;
let mut processes = heim::process::processes();
while let Some(process) = processes.next().await {
let process = process?;
println!("Pid: {}", process.pid());
if process.pid() == current.pid() {
println!("It's-a me, Mario!");
}
println!("Status: {:?}", process.status().await?);
println!("Name: {}", process.name().await?);
println!("Path to executable: {:?}", process.exe().await?);
// …and many other methods available
}
heim::process
API is a bit different from other heim::*
modules, as it involves more async routines
for data loading and includes the custom error type
to handle unknown processes, zombies and such processes for which we do not have the permissions required.
Not all parts are implemented yet (see #106),
but it is usable enough already to build your own top
clone,
as can be seen in the “New users” section below,
so check the docs
and examples for details.
Sensors prototype
Another experimental module heim::sensors
is going to be responsible for temperature and fan sensors eventually,
but fetching that information is amazingly painful,
so there is only temperature sensors
implementation for Linux is available for now.
It seems that for Windows it would require an async WMI client,
which does not exist at all (wmi@13)
and I’m not even sure if it is possible for macOS at all.
Unexpected side crates
As the processes querying for macOS requires interaction with the libproc
library via FFI,
that code was extracted from the heim
sources and published separately as the darwin-libproc-sys and darwin-libproc crates, providing a low-level FFI bindings and idiomatic Rust wrappers correspondingly.
Both of them proudly carry the “experimental” status and covers only few parts of the libproc
API,
but that’s a start!
What’s next?
Missing heim::process
parts will be the major goal for the next month.
Not only the missing “read” methods will be implemented, but the interaction methods too,
like an ability to send signals to the processes, suspend, resume or even kill them.
Runtimes integration
Previous heim
versions were calling sync operations directly in the async functions,
which was bad, obviously, but worked good enough for early prototypes.
Starting from the 0.0.6
version, heim
has its own thread pool to properly run blocking operations
outside of a current execution thread.
It is better than nothing, but not as efficient as it might be,
so it will be replaced with the async-std
crate (#133) soon.
I also do not like the idea of heim
being bound to one specific async runtime,
so there will be the tokio
crate integration too (#82),
which will allow heim
users to choose what underlying implementation they want to use.
Fun time with async_await
I’m very excited that async_await
feature is finally going to be released
as a Rust 1.39 part,
so starting from September heim
will be slowly rewritten with async_await
,
which should reduce the lines of code amount and maintenance burden drastically.
Unfortunately, minimal supported Rust version will be bumped to 1.39 then,
which looks like a fair trade considering how insane it might be sometime to write futures combinators.
New users
Recently announced Nu Shell (a modern shell for the GitHub era)
is using heim
both for the ps
and sys
commands:
Nu
is actively utilizing benefits of the async execution too,
and heim
integration allows it to load displayed data concurrently with ease,
which is vital for a responsive shell and flawless user experience.
It was pretty straightforward to follow your examples. I think I moved to
heim
forsys
in about an hour or so (+ time for testing across platforms)
Let me know if you are using heim
too, I would love to hear about your experience!
P.S.
heim
is the open-source project I’m working on in my spare time.
If you are appreciate it and want to support the project development,
consider making a donation
or becoming the OpenCollective backer/sponsor.