From a80e0ad6bd7d60d540be29859a1e57343cb16576 Mon Sep 17 00:00:00 2001 From: Justin latimer Date: Tue, 25 May 2021 08:21:43 +0000 Subject: [PATCH] Make sure bitfield comments are ordered. --- device_generator/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/device_generator/src/main.rs b/device_generator/src/main.rs index 3fdace2..1162e25 100644 --- a/device_generator/src/main.rs +++ b/device_generator/src/main.rs @@ -164,17 +164,18 @@ mod gen { writeln!(w, "/// `{}` register", register.name)?; } - let mut bitfields = register_bitfields.iter().filter_map(|&(reg,bitfield)| { + let mut bitfields: Vec<&'_ Bitfield> = register_bitfields.iter().filter_map(|&(reg,bitfield)| { if reg == register { Some(bitfield) } else { None } - }).peekable(); + }).collect(); + bitfields.sort_by_key(|b| b.mask); - if bitfields.peek().is_some() { + if bitfields.len() > 0 { writeln!(w, "///")?; writeln!(w, "/// Bitfields:")?; writeln!(w, "///")?; writeln!(w, "/// | Name | Mask (binary) |")?; writeln!(w, "/// | ---- | ------------- |")?; - while let Some(bitfield) = bitfields.next() { + for bitfield in bitfields { writeln!(w, "/// | {} | {:b} |", bitfield.name, bitfield.mask)?; } }