1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
static mut DEBUG_COMMAND: Option<Box<dyn Fn(String)>> = None; static mut DEBUG_RESPONSE: Option<Box<dyn Fn(String)>> = None; pub unsafe fn debug_command_via(f: impl Fn(String) + 'static) { DEBUG_COMMAND = Some(Box::new(f)); } pub unsafe fn debug_response_via(f: impl Fn(String) + 'static) { DEBUG_RESPONSE = Some(Box::new(f)); } pub unsafe fn dont_debug_command() { DEBUG_COMMAND = None; } pub unsafe fn dont_debug_response() { DEBUG_RESPONSE = None; } pub(crate) unsafe fn debug_command(s: String) -> bool { DEBUG_COMMAND.as_ref().map(|f| f(s)).is_some() } pub(crate) unsafe fn debug_response(s: String) -> bool { DEBUG_RESPONSE.as_ref().map(|f| f(s)).is_some() } pub unsafe fn toggle_debug_command() { match DEBUG_COMMAND { None => { println!("Command debug mode is ON"); debug_command_via(|s| print!("{}", s)) } Some(_) => { println!("Command debug mode is OFF"); DEBUG_COMMAND = None } } } pub unsafe fn toggle_debug_response() { match DEBUG_RESPONSE { None => { println!("Response debug mode is ON"); debug_response_via(|s| print!("{}", s)) } Some(_) => { println!("Response debug mode is OFF"); DEBUG_RESPONSE = None } } }