From a822e447f96a095d5b1cf44eaf45a814bc4febee Mon Sep 17 00:00:00 2001 From: guylamar2006 Date: Sat, 9 Nov 2024 20:48:46 -0600 Subject: [PATCH] Future-proof casting bool to i32 If the type of is_press changes in the future, the as cast may not handle the conversion safely and could introduce silent bugs. i32::from: Using i32::from ensures that the conversion is handled safely and explicitly, making it more robust against future changes. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 13ade74..b733a68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ pub extern "C" fn XTestFakeKeyEvent( #[cfg(debug_assertions)] println!("emitting keycode {key:?}"); - dev.emit(&[InputEvent::new_now(EventType::KEY, key.0, is_press as i32)]) + dev.emit(&[InputEvent::new_now(EventType::KEY, key.0, i32::from(is_press))]) .unwrap(); 1 } @@ -140,7 +140,7 @@ pub extern "C" fn XTestFakeButtonEvent( } }; - dev.emit(&[InputEvent::new_now(EventType::KEY, key.0, is_press as i32)]) + dev.emit(&[InputEvent::new_now(EventType::KEY, key.0, i32::from(is_press))]) .unwrap(); 1 }