less unwrap
This commit is contained in:
parent
87f06e9e12
commit
86b895c009
18
src/main.rs
18
src/main.rs
@ -18,9 +18,9 @@ fn listen(socket: &net::UdpSocket) {
|
|||||||
|
|
||||||
if result_str.contains("S0R1") {
|
if result_str.contains("S0R1") {
|
||||||
write_file("Race active".to_string(), "racestate.txt");
|
write_file("Race active".to_string(), "racestate.txt");
|
||||||
write_file("00".to_string(), "rx1.txt");
|
write_file("0".to_string(), "rx1.txt");
|
||||||
write_file("00".to_string(), "rx2.txt");
|
write_file("0".to_string(), "rx2.txt");
|
||||||
write_file("00".to_string(), "rx3.txt");
|
write_file("0".to_string(), "rx3.txt");
|
||||||
}
|
}
|
||||||
if result_str.contains("S0R0") {
|
if result_str.contains("S0R0") {
|
||||||
write_file("Race inactive".to_string(), "racestate.txt");
|
write_file("Race inactive".to_string(), "racestate.txt");
|
||||||
@ -28,18 +28,24 @@ fn listen(socket: &net::UdpSocket) {
|
|||||||
|
|
||||||
if result_str.contains("S0L") {
|
if result_str.contains("S0L") {
|
||||||
// zb sS1L0000000DAF
|
// zb sS1L0000000DAF
|
||||||
let intval = &result_str[3..5].parse::<i32>().unwrap();
|
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
|
||||||
|
if *intval != -1 {
|
||||||
write_file((intval + 1).to_string(), "rx1.txt");
|
write_file((intval + 1).to_string(), "rx1.txt");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if result_str.contains("S1L") {
|
if result_str.contains("S1L") {
|
||||||
let intval = &result_str[3..5].parse::<i32>().unwrap();
|
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
|
||||||
|
if *intval != -1 {
|
||||||
write_file((intval + 1).to_string(), "rx2.txt");
|
write_file((intval + 1).to_string(), "rx2.txt");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if result_str.contains("S2L") {
|
if result_str.contains("S2L") {
|
||||||
let intval = &result_str[3..5].parse::<i32>().unwrap();
|
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
|
||||||
|
if *intval != -1 {
|
||||||
write_file((intval + 1).to_string(), "rx3.txt");
|
write_file((intval + 1).to_string(), "rx3.txt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn write_file(text: String, filename: &str) {
|
fn write_file(text: String, filename: &str) {
|
||||||
let mut file = std::fs::File::create(filename).expect("create failed");
|
let mut file = std::fs::File::create(filename).expect("create failed");
|
||||||
|
Loading…
Reference in New Issue
Block a user