Browse Source

firmware: use let-else clause to improve code readability on `merge_sections` function

Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
pull/67/head
Zhouqi Jiang 5 months ago
committed by Andelf
parent
commit
ea42f04dfe
  1. 7
      src/firmware.rs

7
src/firmware.rs

@ -41,7 +41,9 @@ pub enum Firmware {
impl Firmware { impl Firmware {
/// Merge sections, and fill gap with 0xff /// Merge sections, and fill gap with 0xff
pub fn merge_sections(self) -> Result<Self> { pub fn merge_sections(self) -> Result<Self> {
if let Firmware::Sections(mut sections) = self { let Firmware::Sections(mut sections) = self else {
return Ok(self);
};
sections.sort_by_key(|s| s.address); sections.sort_by_key(|s| s.address);
let mut merged = vec![]; let mut merged = vec![];
@ -67,9 +69,6 @@ impl Firmware {
} }
merged.push(last); merged.push(last);
Ok(Firmware::Sections(merged)) Ok(Firmware::Sections(merged))
} else {
Ok(self)
}
} }
} }

Loading…
Cancel
Save