Skip to content

Commit

Permalink
Remove let ... else for compatibility with Rust 1.63.
Browse files Browse the repository at this point in the history
  • Loading branch information
KarsMulder committed Oct 7, 2024
1 parent bb6dcaf commit d4c0fa1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/data/hid_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ impl UsagePagesState {
let page_id: u16 = ((scancode_u32 & 0xffff0000) >> 16) as u16;
let usage_id: u16 = (scancode_u32 & 0x0000ffff) as u16;

let UsagePagesState::Available(pages) = self else { return None };
let pages = match self {
UsagePagesState::Available(pages) => pages,
UsagePagesState::NotAvailable => return None,
};

match pages.binary_search_by_key(&page_id, |page| page.id) {
Err(_) => Some(UsageInfo { page_id, usage_id, names: UsageNames::Unknown }),
Expand Down
18 changes: 11 additions & 7 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ impl Set {
/// Returns [i32::MIN, i32::MAX] \ self.
pub fn complement(&self) -> Set {

let (Some(first_interval), Some(last_interval)) = (self.intervals.first(), self.intervals.last()) else {
// If first() and last() return None, then the intervals vector is empty, which means that this
// is the empty set and the complement is the universe set [i32::MIN, i32::MAX].
return Set {
intervals: vec![Interval::new(i32::MIN, i32::MAX)]
let (first_interval, last_interval) = match (self.intervals.first(), self.intervals.last()) {
(Some(first), Some(last)) => (first, last),
_ => {
// If first() and last() return None, then the intervals vector is empty, which means that this
// is the empty set and the complement is the universe set [i32::MIN, i32::MAX].
return Set {
intervals: vec![Interval::new(i32::MIN, i32::MAX)]
}
}
};

Expand All @@ -201,8 +204,9 @@ impl Set {
result.push(Interval::new(i32::MIN, first_interval.min.checked_sub(1).unwrap()));
}
for interval_pair in self.intervals.windows(2) {
let [interval_a, interval_b] = interval_pair else {
panic!("slice::windows(2) did return a window that did not contain two elements.")
let [interval_a, interval_b] = match interval_pair {
[a, b] => [a, b],
_ => panic!("slice::windows(2) did return a window that did not contain two elements."),
};

if interval_b.min > interval_a.max.saturating_add(1) {
Expand Down

0 comments on commit d4c0fa1

Please sign in to comment.