Expand description
Rust bindings for libpcuid CPU detection and feature extraction library.
rust-cpuid
provides a high-level interface for getting information
about the features of the CPU that runs your code. All the essential
work is done by the libcpuid
C library and exposed through Rust’s
FFI mechanism as a simple and convenient API.
§Available features
- CPU vendor, brand and codename detection
- information about number of cores (both physical and logical)
- cache size
- clock frequency
§Installation
First - download, and build libcpuid as described in the
readme. Install it by running make install
(you may want to run ldconfig
afterwards).
Add to your Cargo.toml
:
[dependencies]
cpuid = "*"
§Example
extern crate cpuid;
fn main () {
match cpuid::identify() {
Ok(info) => {
println!("Found: {} CPU, model: {}", info.vendor, info.codename);
println!("The full brand string is: {}", info.brand);
println!("Hardware AES support: {}", if info.has_feature(cpuid::CpuFeature::AES) { "yes" } else { "no" });
},
Err(err) => println!("cpuid error: {}", err),
};
match cpuid::clock_frequency() {
Some(frequency) => println!("CPU speed: {} MHz", frequency),
None => println!("Couldn't get CPU speed."),
};
}
Structs§
- CpuInfo
- A struct holding information about CPU features.
Enums§
- CpuFeature
- CPU feature identifiers.
Functions§
- clock_
frequency - Gets the CPU clock frequency in MHz.
- error
- Returns last libcpuid error string.
- identify
- Tries to identify the current CPU and its features.
- is_
present - Checks if the CPUID instruction is present.
- version
- Returns libcpuid version string.