Leave a note of a nightly feature feedback received on discord.
authorSunil Nimmagadda <sunil@nimmagadda.net>
Wed, 04 Jan 2023 15:58:49 +0530
changeset 11 0d19b7de6f5d
parent 10 aef7eb135a0c
child 12 a46fd16cc293
Leave a note of a nightly feature feedback received on discord.
src/vrrpv2.rs
--- a/src/vrrpv2.rs	Tue Jan 03 20:35:05 2023 +0530
+++ b/src/vrrpv2.rs	Wed Jan 04 15:58:49 2023 +0530
@@ -77,6 +77,13 @@
     })(input)
 }
 
+// Nightly has a nicer array_chunks API to express it more succinctly.
+// let mut chunks = bytes.array_chunks(2);
+// let mut sum = chunks.map(u16::from_ne_bytes).map(|b| b as u32).sum::<u32>();
+// // handle the remainder
+// if let Some([b]) = chunks.remainder() {
+//     sum += *b as u32
+// }
 fn validate_checksum(bytes: &[u8]) -> bool {
     let mut sum: u32 = bytes.chunks(2).fold(0, |acc: u32, x| {
         acc + u32::from(u16::from_ne_bytes(x.try_into().unwrap()))