@@ -42,7 +42,7 @@ impl Led {
42
42
* self as u8
43
43
}
44
44
45
- pub fn from_u8 ( value : u8 ) -> Option < Self > {
45
+ pub const fn from_u8 ( value : u8 ) -> Option < Self > {
46
46
match value {
47
47
0xAA => Some ( Self :: Red ) ,
48
48
0xBB => Some ( Self :: Green ) ,
@@ -63,7 +63,7 @@ impl Action {
63
63
* self as u8
64
64
}
65
65
66
- pub fn from_u8 ( value : u8 ) -> Option < Self > {
66
+ pub const fn from_u8 ( value : u8 ) -> Option < Self > {
67
67
match value {
68
68
0x01 => Some ( Self :: On ) ,
69
69
0x02 => Some ( Self :: Off ) ,
@@ -147,18 +147,18 @@ mod app {
147
147
let msg = receiver. recv ( ) . await ;
148
148
match msg {
149
149
Ok ( data) => {
150
- if let Some ( led) = Led :: from_u8 ( data[ 0 ] ) {
151
- if let Some ( action) = Action :: from_u8 ( data[ 1 ] ) {
152
- match ( led, action) {
153
- ( Led :: Red , Action :: On ) => led_red. on ( ) ,
154
- ( Led :: Red , Action :: Off ) => led_red. off ( ) ,
155
- ( Led :: Green , Action :: On ) => led_green. on ( ) ,
156
- ( Led :: Green , Action :: Off ) => led_green. off ( ) ,
157
- ( Led :: Blue , Action :: On ) => led_blue. on ( ) ,
158
- ( Led :: Blue , Action :: Off ) => led_blue. off ( ) ,
159
- }
160
- debug ! ( "Received: {:?} {:?}" , led, action) ;
150
+ if let ( Some ( led) , Some ( action) ) =
151
+ ( Led :: from_u8 ( data[ 0 ] ) , Action :: from_u8 ( data[ 1 ] ) )
152
+ {
153
+ match ( led, action) {
154
+ ( Led :: Red , Action :: On ) => led_red. on ( ) ,
155
+ ( Led :: Red , Action :: Off ) => led_red. off ( ) ,
156
+ ( Led :: Green , Action :: On ) => led_green. on ( ) ,
157
+ ( Led :: Green , Action :: Off ) => led_green. off ( ) ,
158
+ ( Led :: Blue , Action :: On ) => led_blue. on ( ) ,
159
+ ( Led :: Blue , Action :: Off ) => led_blue. off ( ) ,
161
160
}
161
+ debug ! ( "Received: {:?} {:?}" , led, action) ;
162
162
}
163
163
}
164
164
Err ( _) => {
0 commit comments