#fetch #hardware #pci

已删除 pci_fetch

获取连接的PCI设备信息

2.2.1 2021年6月24日
2.1.0 2021年6月24日
2.0.0 2021年6月24日
1.0.0 2021年6月23日
0.1.0 2021年6月23日

#pci 中排名 18

MIT 许可证

21KB
364

pci_fetch

获取连接的PCI设备信息;基本上是Rust 🦀中的"lspci"。

Version Docs

用法

将以下内容添加到您的项目的Cargo.toml文件中

pci_fetch = "2.1.0"

示例

use pci_fetch::classes::DeviceClass;
use pci_fetch::linux::*;
use pci_fetch::traits::*;
use std::path::PathBuf;

fn main() {
    // Instantiate a new PCIDevice so we can get to know it a bit.
    let mut device: PCIDevice = PCIDevice::new(PathBuf::from("/sys/bus/pci/devices/0000:00:02.0"));
    // This little guy is important :)
    device.init();

    println!("Path: {:?}", device.path());         // e.g. /sys/bus/pci/devices/0000:00:02.0
    println!("Address: {}", device.address());     // e.g. 00:02.0
    println!("Class ID: {}", device.class_id());   // e.g. 03
    println!("Class Name: {}", device.class_name()); // e.g. Display Controller

    // Alternatively, we can get information on PCI devices through fetching them in bulk!

    // Return a list of the available PCI devices of a specific class.
    //    Example: This should return all the available GPUs but with little amount of information.
    let list: Vec<PCIDevice> = fetch_by_class(DeviceClass::DisplayController);
    println!("{:?}", list);

    // Return a list of the available PCI devices of a specific class with detailed information.
    //    Example: This should return all the available GPUs.
    let gpus: Vec<PCIDevice> = fetch_by_class_detailed(DeviceClass::DisplayController);
    println!("{:?}", gpus);

    // Return a list of available PCI devices with detailed information.
    let detailed_list: Vec<PCIDevice> = fetch_detailed();
    println!("{:?}", detailed_list);
}


平台支持

平台 支持
Linux

无运行时依赖