Rust

Crate root

Module
What utopia_system defines at its root.

Contents

use utopia_system::CpuTimes;
Rust
pub struct CpuTimes

Time spent by all CPUs in each state since boot, in clock ticks, summed over the per-CPU lines of /proc/stat.

Only cpuN lines count, not the aggregate cpu line. Fields are split on single spaces, and a later line for the same CPU replaces an earlier one.

use utopia_system::Io;
Rust
pub struct Io

Read and write volume of a disk over a sampling period, in MiB.

Each volume is an integer when the division is exact, a float otherwise.

use utopia_system::Machine;
Rust
pub struct Machine

This machine. File reads are of /proc and /sys pseudo-files, which the kernel serves from memory; sysctl and wmic (macOS and Windows only) run as child processes.

use utopia_system::System;
Rust
pub struct System<H: Host = Machine>

Facts and measurements of a machine, read through a Host.

use utopia_system::Traffic;
Rust
pub struct Traffic

Download and upload volume of a network interface, in MiB rounded to two decimals.

use utopia_system::Arch;
Rust
pub enum Arch

A processor architecture family.

use utopia_system::Error;
Rust
pub enum Error

Why a measurement failed.

use utopia_system::Uname;
Rust
pub enum Uname

A field of the system's identity, as Host::uname reports it.

use utopia_system::Host;
Rust
pub trait Host

Where a System reads the machine from: identity, files, commands, directories, disk space and the clock.

Implemented byMachine
use utopia_system::count_cpu_list;
Rust
pub fn count_cpu_list(list: &[u8]) -> Result<i64, Error>

The number of CPUs in a Linux CPU list such as 0-3,5,7-8.

Ranges whose bounds are not numeric or are reversed count nothing. A count beyond i64 fails with Error::Type.

use utopia_system::count_processors;
Rust
pub fn count_processors(cpuinfo: &[u8]) -> usize

The number of processors in /proc/cpuinfo content: lines starting with processor.

use utopia_system::diskstats;
Rust
pub fn diskstats(content: &[u8]) -> Option<IndexMap<String, Vec<Vec<u8>>>>

The lines of /proc/diskstats content, split into fields and keyed by disk name; None when the content is empty or "0".

Each non-empty line is trimmed, each run of tabs becomes one space, and the line is split on single spaces. The key is the third field ("" when there is none), and a later line replaces an earlier one with the same key.

use utopia_system::env;
Rust
pub fn env(name: &str) -> Option<String>

An environment variable, or None when it is unset, empty or "0".

A variable that is not valid Unicode counts as unset.

use utopia_system::env_or;
Rust
pub fn env_or<'a>(name: &str, default: &'a str) -> std::borrow::Cow<'a, str>

An environment variable, or default when it is unset, empty or "0".

The default is borrowed, not copied: compare the result as it is, or call Cow::into_owned to keep it.

use utopia_system::env_raw;
Rust
pub fn env_raw(name: &str) -> Option<String>

An environment variable as it is, empty strings and "0" included; None only when it is unset (or not valid Unicode).

use utopia_system::env_value;
Rust
pub fn env_value(raw: Option<String>) -> Option<String>

The rule env applies to a raw value: one that is empty or "0" is no value.

use utopia_system::meminfo;
Rust
pub fn meminfo(content: &[u8], field: &str) -> Option<i64>

A field of /proc/meminfo content, such as MemTotal, in MiB rounded down; None when it is missing.

The value is the first <field>: followed by whitespace and digits, read as KiB.

use utopia_system::proc_stat_total;
Rust
pub fn proc_stat_total(content: &[u8]) -> Option<CpuTimes>

The CpuTimes of /proc/stat content; None when the content is empty or "0".