From 1daa5d5304b35a4c0e1fa870c63faea92d0e98f0 Mon Sep 17 00:00:00 2001 From: Paul Schulze Date: Tue, 5 Mar 2024 18:53:26 +0100 Subject: [PATCH] [code] iterators all the way --- src/main.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6c17891..91e7010 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,12 +45,10 @@ where fn trim_end(line: &[u8]) -> usize { let mut end = line.len(); - for ch in line.iter().rev() { - if *ch != b'\r' && *ch != b'\n' && *ch != b'\t' { - break; - } - end -= 1; - } + line.iter() + .rev() + .take_while(|ch| ch.is_ascii_whitespace()) + .for_each(|_| end -= 1); end }