From e1c9ba6ff2bb5a3a605171e7e3b9b84894df21b2 Mon Sep 17 00:00:00 2001 From: fox0 <15684995+fox0@users.noreply.github.com> Date: Sat, 12 Oct 2024 20:52:08 +0700 Subject: [PATCH] join: Fix clippy::int_plus_one and add a assert --- text/join.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/text/join.rs b/text/join.rs index 8d959ad6..1b6a3718 100644 --- a/text/join.rs +++ b/text/join.rs @@ -103,22 +103,28 @@ fn process_files2( let mut res: Vec = Vec::new(); for num in order { let f_num: Vec<&str> = num.split('.').collect(); + assert_eq!(f_num.len(), 2); + let mut n: usize = f_num[1].parse()?; + n -= 1; if f_num[0] == "1" { - if fields1.len() <= f_num[1].parse::()? - 1 { + if fields1.len() <= n { if let Some(e) = &e { res.push(e.to_string()); } } else { - res.push(fields1[f_num[1].parse::()? - 1].clone()); + res.push(fields1[n].clone()); } } else if f_num[0] == "2" { - if fields2.len() <= f_num[1].parse::()? - 1 { + if fields2.len() <= n { if let Some(e) = &e { res.push(e.to_string()); } } else { - res.push(fields2[f_num[1].parse::()? - 1].clone()); + res.push(fields2[n].clone()); } + } else { + // TODO: + panic!("f_num[0] not in (1, 2)"); } } if v == 0 {