Browse Source

Refactor to use more match patterns

Kevin Lee 2 years ago
parent
commit
5378606b8f
2 changed files with 17 additions and 25 deletions
  1. 13 25
      Nixie_Firmware_Rust/src/ds3231.rs
  2. 4 0
      Nixie_Firmware_Rust/src/main.rs

+ 13 - 25
Nixie_Firmware_Rust/src/ds3231.rs

@@ -1,7 +1,5 @@
 use field_offset::offset_of;
-use stm32l4xx_hal::{
-    prelude::{_embedded_hal_blocking_i2c_Read, _embedded_hal_blocking_i2c_Write},
-};
+use stm32l4xx_hal::prelude::{_embedded_hal_blocking_i2c_Read, _embedded_hal_blocking_i2c_Write};
 use tock_registers::{
     interfaces::{ReadWriteable, Readable},
     register_bitfields, register_structs,
@@ -136,28 +134,18 @@ pub fn in_dst(weekday: Weekday, day: u32, month: u32, hour_24: u32) -> bool {
     match month {
         0..=2 | 12.. => false,
         4..=10 => true,
-        3 => {
-            if prev_sunday < 8 {
-                false
-            } else if prev_sunday > 14 {
-                true
-            } else if prev_sunday == day as i32 {
-                hour_24 >= 2
-            } else {
-                true
-            }
-        }
-        11 => {
-            if prev_sunday <= 0 {
-                true
-            } else if day > 7 {
-                false
-            } else if prev_sunday == day as i32 {
-                hour_24 < 2
-            } else {
-                false
-            }
-        }
+        3 => match prev_sunday {
+            ..8 => false,
+            15.. => true,
+            day => hour_24 >= 2,
+            _ => true,
+        },
+        11 => match prev_sunday {
+            ..=0 => true,
+            8.. => false,
+            day => hour_24 < 2,
+            _ => false,
+        },
     }
 }
 

+ 4 - 0
Nixie_Firmware_Rust/src/main.rs

@@ -1,7 +1,11 @@
 #![cfg_attr(test, allow(unused_imports))]
 #![cfg_attr(not(test), no_std)]
 #![cfg_attr(not(test), no_main)]
+
 // #![feature(generic_const_exprs)]
+#![feature(half_open_range_patterns)]
+#![feature(exclusive_range_pattern)]
+
 
 // custom panic handler
 #[cfg(not(test))]