Skip to content

Commit c932b07

Browse files
committed
InputVerifier: use let ... else when converting flags and buttons
Bug: 245989146 Test: enable the verifier, check everything works as usual Flag: EXEMPT refactor Change-Id: I3debc83da82168f9c5a7e3eccb2f8dc6edbabaed
1 parent 21a4653 commit c932b07

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

libs/input/rust/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,36 +133,33 @@ fn process_movement(
133133
flags: u32,
134134
button_state: u32,
135135
) -> String {
136-
let motion_flags = MotionFlags::from_bits(flags);
137-
if motion_flags.is_none() {
136+
let Some(motion_flags) = MotionFlags::from_bits(flags) else {
138137
panic!(
139138
"The conversion of flags 0x{:08x} failed, please check if some flags have not been \
140139
added to MotionFlags.",
141140
flags
142141
);
143-
}
144-
let motion_action_button = MotionButton::from_bits(action_button);
145-
if motion_action_button.is_none() {
142+
};
143+
let Some(motion_action_button) = MotionButton::from_bits(action_button) else {
146144
panic!(
147145
"The conversion of action button 0x{action_button:08x} failed, please check if some \
148146
buttons need to be added to MotionButton."
149147
);
150-
}
151-
let motion_button_state = MotionButton::from_bits(button_state);
152-
if motion_button_state.is_none() {
148+
};
149+
let Some(motion_button_state) = MotionButton::from_bits(button_state) else {
153150
panic!(
154151
"The conversion of button state 0x{button_state:08x} failed, please check if some \
155152
buttons need to be added to MotionButton."
156153
);
157-
}
154+
};
158155
let result = verifier.process_movement(NotifyMotionArgs {
159156
device_id: DeviceId(device_id),
160157
source: Source::from_bits(source).unwrap(),
161158
action,
162-
action_button: motion_action_button.unwrap(),
159+
action_button: motion_action_button,
163160
pointer_properties,
164-
flags: motion_flags.unwrap(),
165-
button_state: motion_button_state.unwrap(),
161+
flags: motion_flags,
162+
button_state: motion_button_state,
166163
});
167164
match result {
168165
Ok(()) => "".to_string(),

0 commit comments

Comments
 (0)