Refactor a match expression

This commit is contained in:
Mirna
2020-11-04 20:25:30 +02:00
parent c232f2344c
commit 0eaa2b5291

View File

@@ -19,7 +19,6 @@ mod example {
#[cfg(feature = "with_nfc")] #[cfg(feature = "with_nfc")]
mod example { mod example {
use super::Console; use super::Console;
use super::Write; use super::Write;
use libtock_core::result::CommandError; use libtock_core::result::CommandError;
@@ -160,29 +159,26 @@ mod example {
let mut is_enabled = false; let mut is_enabled = false;
let mut state_change_counter = 0; let mut state_change_counter = 0;
loop { loop {
match is_enabled { if is_enabled {
true => { let mut rx_buf = [0; 256];
let mut rx_buf = [0; 256]; loop {
loop { receive_packet(&mut console, &mut rx_buf);
receive_packet(&mut console, &mut rx_buf); // If the reader restarts the communication and we can't
// If the reader restarts the communication and we can't // reply to the received packet, then disable the tag.
// reply to the received packet, then disable the tag. if !transmit_reply(&mut console, &timer, &rx_buf) {
if !transmit_reply(&mut console, &timer, &rx_buf) { is_enabled = false;
is_enabled = false; break;
break;
}
} }
} }
false => { } else {
NfcTag::enable_emulation(); NfcTag::enable_emulation();
// Configure Type 4 tag // Configure Type 4 tag
if NfcTag::configure(4) { if NfcTag::configure(4) {
is_enabled = true; is_enabled = true;
}
} }
} }
state_change_counter += 1; state_change_counter += 1;
if state_change_counter > 100 && is_enabled == false { if !is_enabled && state_change_counter > 100 {
break; break;
} }
} }