Adds a cleanup for the macro
This commit is contained in:
parent
de9f497a00
commit
dce5b8d883
52
src/main.rs
52
src/main.rs
|
|
@ -29,27 +29,29 @@ struct Args {
|
|||
}
|
||||
|
||||
macro_rules! list_actions {
|
||||
($($id1:literal , $proj1:ident, $action1:ident),+ ) => {
|
||||
|
||||
|
||||
vec![
|
||||
$((
|
||||
$id1,
|
||||
|
||||
Box::new(move || {
|
||||
match $proj1.lock().unwrap().$action1() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!(
|
||||
"[ERROR] An error occurend while sending a ({}) message",
|
||||
stringify!($action1)
|
||||
);
|
||||
println!(" {}", e)
|
||||
}
|
||||
};
|
||||
}),
|
||||
),)+
|
||||
]
|
||||
($proj:ident, $($id:literal, $action:ident),+ ) => {
|
||||
{
|
||||
let mut temp_vec:Vec<(u8, Box<(dyn Fn() + Send + 'static)>)> = Vec::new();
|
||||
$(
|
||||
let proj = Arc::clone(&$proj);
|
||||
temp_vec.push((
|
||||
$id,
|
||||
Box::new(move || {
|
||||
match proj.lock().unwrap().$action() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!(
|
||||
"[ERROR] An error occurend while sending a ({}) message",
|
||||
stringify!($action)
|
||||
);
|
||||
println!(" {}", e)
|
||||
}
|
||||
};
|
||||
}),
|
||||
));
|
||||
)+
|
||||
temp_vec
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -84,12 +86,6 @@ fn main() {
|
|||
"admin1",
|
||||
"panasonic",
|
||||
)));
|
||||
let proj1 = Arc::clone(&proj);
|
||||
let proj2 = Arc::clone(&proj);
|
||||
|
||||
// proj.lock().unwrap().shutter_on().unwrap();
|
||||
// proj.lock().unwrap().shutter_off().unwrap();
|
||||
// proj.lock().unwrap().get_osd().unwrap();
|
||||
|
||||
let mut output_interface =
|
||||
create_output_interface(args.midi_output, "Rusty MIDI Commander Output");
|
||||
|
|
@ -98,6 +94,6 @@ fn main() {
|
|||
args.midi_input.unwrap(),
|
||||
"Rusty MIDI Commander Input",
|
||||
&mut output_interface,
|
||||
list_actions!(3, proj1, shutter_on, 4, proj2, shutter_off),
|
||||
list_actions!(proj, 3, shutter_on, 4, shutter_off),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue