treewide: set up rustfmt and taplo with custom rules

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I794f9152bb02e3dd91c9738369b94fc66a6a6964
This commit is contained in:
raf 2026-02-19 01:42:28 +03:00
commit ffae695240
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
27 changed files with 1851 additions and 1618 deletions

View file

@ -1,5 +1,5 @@
[package]
name = "scanner-power"
name = "scanner-power"
version.workspace = true
edition.workspace = true
license.workspace = true
@ -7,9 +7,9 @@ authors.workspace = true
[dependencies]
pscand-core.workspace = true
toml.workspace = true
toml.workspace = true
[lib]
name = "scanner_power"
path = "src/lib.rs"
crate-type = ["cdylib"]
crate-type = [ "cdylib" ]
name = "scanner_power"
path = "src/lib.rs"

View file

@ -1,96 +1,104 @@
use pscand_core::helpers::PowerHelper;
use pscand_core::scanner::{MetricValue, Scanner};
use std::collections::HashMap;
use std::time::Duration;
use std::{
collections::HashMap,
time::Duration,
};
use pscand_core::{
helpers::PowerHelper,
scanner::{
MetricValue,
Scanner,
},
};
struct PowerScanner;
#[no_mangle]
pub extern "C" fn pscand_scanner() -> *mut std::os::raw::c_void {
Box::into_raw(Box::new(PowerScanner)) as *mut std::os::raw::c_void
pub extern fn pscand_scanner() -> *mut std::os::raw::c_void {
Box::into_raw(Box::new(PowerScanner)) as *mut std::os::raw::c_void
}
impl Default for PowerScanner {
fn default() -> Self {
Self
}
fn default() -> Self {
Self
}
}
impl Scanner for PowerScanner {
fn name(&self) -> &'static str {
"power"
fn name(&self) -> &'static str {
"power"
}
fn interval(&self) -> Duration {
Duration::from_secs(2)
}
fn init(&mut self, _config: &toml::Value) -> pscand_core::Result<()> {
Ok(())
}
fn collect(&self) -> pscand_core::Result<HashMap<String, MetricValue>> {
let mut metrics = HashMap::new();
if let Ok(Some(battery)) = PowerHelper::battery_info() {
metrics.insert(
"battery_present".to_string(),
MetricValue::from_bool(battery.present),
);
metrics.insert(
"battery_charge_percent".to_string(),
MetricValue::Integer(battery.charge_percent as i64),
);
metrics.insert(
"battery_voltage_v".to_string(),
MetricValue::from_f64(battery.voltage),
);
metrics.insert(
"battery_power_now_mw".to_string(),
MetricValue::Integer(battery.power_now),
);
metrics.insert(
"battery_status".to_string(),
MetricValue::from_string(&battery.status),
);
}
fn interval(&self) -> Duration {
Duration::from_secs(2)
}
fn init(&mut self, _config: &toml::Value) -> pscand_core::Result<()> {
Ok(())
}
fn collect(&self) -> pscand_core::Result<HashMap<String, MetricValue>> {
let mut metrics = HashMap::new();
if let Ok(Some(battery)) = PowerHelper::battery_info() {
metrics.insert(
"battery_present".to_string(),
MetricValue::from_bool(battery.present),
);
metrics.insert(
"battery_charge_percent".to_string(),
MetricValue::Integer(battery.charge_percent as i64),
);
metrics.insert(
"battery_voltage_v".to_string(),
MetricValue::from_f64(battery.voltage),
);
metrics.insert(
"battery_power_now_mw".to_string(),
MetricValue::Integer(battery.power_now),
);
metrics.insert(
"battery_status".to_string(),
MetricValue::from_string(&battery.status),
);
if let Ok(supplies) = PowerHelper::power_supplies() {
for (name, info) in supplies {
if let Some(status) = info.get("status") {
metrics.insert(
format!("supply_{}_status", name),
MetricValue::from_string(status),
);
}
if let Ok(supplies) = PowerHelper::power_supplies() {
for (name, info) in supplies {
if let Some(status) = info.get("status") {
metrics.insert(
format!("supply_{}_status", name),
MetricValue::from_string(status),
);
}
if let Some(online) = info.get("online") {
metrics.insert(
format!("supply_{}_online", name),
MetricValue::from_bool(online == "1"),
);
}
if let Some(capacity) = info.get("capacity") {
if let Ok(cap) = capacity.parse::<u32>() {
metrics.insert(
format!("supply_{}_capacity", name),
MetricValue::Integer(cap as i64),
);
}
}
}
if let Some(online) = info.get("online") {
metrics.insert(
format!("supply_{}_online", name),
MetricValue::from_bool(online == "1"),
);
}
if let Ok(state) = PowerHelper::suspend_state() {
if let Some(capacity) = info.get("capacity") {
if let Ok(cap) = capacity.parse::<u32>() {
metrics.insert(
"suspend_state".to_string(),
MetricValue::from_string(&state),
format!("supply_{}_capacity", name),
MetricValue::Integer(cap as i64),
);
}
}
Ok(metrics)
}
}
fn cleanup(&mut self) -> pscand_core::Result<()> {
Ok(())
if let Ok(state) = PowerHelper::suspend_state() {
metrics.insert(
"suspend_state".to_string(),
MetricValue::from_string(&state),
);
}
Ok(metrics)
}
fn cleanup(&mut self) -> pscand_core::Result<()> {
Ok(())
}
}