From 86b895c009093139745a3cbd62b9341aa3bf51e1 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Thu, 2 Jan 2020 22:14:38 +0100 Subject: [PATCH] less unwrap --- src/main.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 665b471..d83afed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,9 @@ fn listen(socket: &net::UdpSocket) { if result_str.contains("S0R1") { write_file("Race active".to_string(), "racestate.txt"); - write_file("00".to_string(), "rx1.txt"); - write_file("00".to_string(), "rx2.txt"); - write_file("00".to_string(), "rx3.txt"); + write_file("0".to_string(), "rx1.txt"); + write_file("0".to_string(), "rx2.txt"); + write_file("0".to_string(), "rx3.txt"); } if result_str.contains("S0R0") { write_file("Race inactive".to_string(), "racestate.txt"); @@ -28,16 +28,22 @@ fn listen(socket: &net::UdpSocket) { if result_str.contains("S0L") { // zb sS1L0000000DAF - let intval = &result_str[3..5].parse::().unwrap(); - write_file((intval + 1).to_string(), "rx1.txt"); + let intval = &result_str[3..5].parse::().unwrap_or(-1); + if *intval != -1 { + write_file((intval + 1).to_string(), "rx1.txt"); + } } if result_str.contains("S1L") { - let intval = &result_str[3..5].parse::().unwrap(); - write_file((intval + 1).to_string(), "rx2.txt"); - } + let intval = &result_str[3..5].parse::().unwrap_or(-1); + if *intval != -1 { + write_file((intval + 1).to_string(), "rx2.txt"); + } +} if result_str.contains("S2L") { - let intval = &result_str[3..5].parse::().unwrap(); - write_file((intval + 1).to_string(), "rx3.txt"); + let intval = &result_str[3..5].parse::().unwrap_or(-1); + if *intval != -1 { + write_file((intval + 1).to_string(), "rx3.txt"); + } } }