another shrimple macro!

This commit is contained in:
IntoTheNight 2023-07-09 17:18:41 +05:30
parent 7ac33efcbc
commit 4252719a72
2 changed files with 29 additions and 27 deletions

View file

@ -23,36 +23,26 @@ impl DeviceTree {
let mut dt = Self {
devices: HashMap::new(),
};
// Human input devices
{
dt.devices.insert("Mice".to_string(), Vec::new());
dt.devices.insert("Keyboards".to_string(), Vec::new());
dt.devices.insert("Controllers".to_string(), Vec::new());
// Human Input Devices that do not fit into other catagories go in this spot
dt.devices.insert("Generic HIDs".to_string(), Vec::new());
}
{
dt.devices.insert("Disk Drives".to_string(), Vec::new());
dt.devices.insert("CD Drives".to_string(), Vec::new());
}
dt.devices.insert("Batteries".to_string(), Vec::new());
dt.devices.insert("Monitors".to_string(), Vec::new());
dt.devices.insert("GPUs".to_string(), Vec::new());
dt.devices.insert("CPUs".to_string(), Vec::new());
dt.devices.insert("USB".to_string(), Vec::new());
dt.devices.insert("Serial Ports".to_string(), Vec::new());
dt.devices.insert("Cameras".to_string(), Vec::new());
dt.devices
.insert("Biometric Devices".to_string(), Vec::new());
device_tree!(dt, [
"Mice",
"Keyboards",
"Controllers",
"Generic HIDs",
"Disk Drives",
"CD Drives",
"Batteries",
"Monitors",
"GPUs",
"CPUs",
"USB",
"Serial Ports",
"Cameras",
"Biometric Devices",
]);
dt
}
}
use crate::utils::TAB;
use crate::{utils::TAB, device_tree};
use crate::tab;
impl fmt::Display for DeviceTree {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

View file

@ -14,3 +14,15 @@ macro_rules! tab {
TAB.repeat($num)
}
}
// NOTE: this only reduces the code duplication in source code not in generated code!
// Written by Yours Truly: Munir
/// A simple macro to reduce code duplication when we insert device types into the device tree
#[macro_export]
macro_rules! device_tree {
($devtree:expr, $dev_type_vec:expr) => {
for each_device_type in $dev_type_vec {
$devtree.devices.insert(each_device_type.to_string(), Vec::new());
}
};
}