#derive #struct #directory #read #macro

structfromdir

从目录读取到 Rust 结构体的派生宏

1 个不稳定版本

0.1.0 2023年4月22日

文件系统 中排名第 1674

MIT 许可证

4KB
52 代码行

structfromdir

一个 Rust 派生宏,允许从目录读取结构体值。

尚未准备好用于生产使用,仍处于高度开发中,许多功能尚未实现或可能会意外崩溃。

用法

use structfromdir::FromDir;

#[derive(FromDir, Debug)]
struct Files {
    capacity: u8,
    energy_now: u64,
}

fn main() {
    let files = Files::from_dir("/sys/class/power_supply/BAT0");
    println!("{:?}", files);
}

结果

Ok(Files { capacity: 68, energy_now: 38780000 })

依赖项

~300–760KB
~18K SLoC