migrate to rust
This commit is contained in:
27
src/lsblk.rs
Normal file
27
src/lsblk.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::io;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Report {
|
||||
pub blockdevices: Vec<BlockDev>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct BlockDev {
|
||||
pub name: String,
|
||||
#[serde(rename = "maj:min")]
|
||||
pub maj_min: String,
|
||||
pub rm: bool,
|
||||
pub size: String,
|
||||
pub ro: bool,
|
||||
#[serde(rename = "type")]
|
||||
pub dev_type: String,
|
||||
pub mountpoints: Vec<Option<String>>,
|
||||
#[serde(default)]
|
||||
pub children: Vec<BlockDev>,
|
||||
}
|
||||
|
||||
pub fn report() -> io::Result<Report> {
|
||||
let output = Command::new("lsblk").arg("--json").output()?;
|
||||
Ok(serde_json::from_slice(output.stdout.as_slice()).unwrap())
|
||||
}
|
Reference in New Issue
Block a user