Skip to content

Commit 247460a

Browse files
authored
Remove a bunch of unnecessary Box<dyn> (#898)
1 parent 1e25b4a commit 247460a

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

espflash/src/connection/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Connection {
168168
);
169169

170170
for (_, reset_strategy) in zip(0..MAX_CONNECT_ATTEMPTS, reset_sequence.iter().cycle()) {
171-
match self.connect_attempt(reset_strategy) {
171+
match self.connect_attempt(reset_strategy.as_ref()) {
172172
Ok(_) => {
173173
return Ok(());
174174
}
@@ -182,8 +182,7 @@ impl Connection {
182182
}
183183

184184
/// Try to connect to a device.
185-
#[allow(clippy::borrowed_box)]
186-
fn connect_attempt(&mut self, reset_strategy: &Box<dyn ResetStrategy>) -> Result<(), Error> {
185+
fn connect_attempt(&mut self, reset_strategy: &dyn ResetStrategy) -> Result<(), Error> {
187186
// If we're doing no_sync, we're likely communicating as a pass through
188187
// with an intermediate device to the ESP32
189188
if self.before_operation == ResetBeforeOperation::NoResetNoSync {

espflash/src/image_format/idf.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl<'a> IdfBootloaderFormat<'a> {
586586
}
587587

588588
/// Returns an iterator over the [Segment]'s that should be placed in flash.
589-
pub fn flash_segments<'b>(self) -> Box<dyn Iterator<Item = Segment<'b>> + 'b>
589+
pub fn flash_segments<'b>(self) -> impl Iterator<Item = Segment<'b>>
590590
where
591591
'a: 'b,
592592
{
@@ -605,19 +605,17 @@ impl<'a> IdfBootloaderFormat<'a> {
605605
data: self.flash_segment.data,
606606
};
607607

608-
Box::new(
609-
once(bootloader_segment)
610-
.chain(once(partition_table_segment))
611-
.chain(once(app_segment)),
612-
)
608+
once(bootloader_segment)
609+
.chain(once(partition_table_segment))
610+
.chain(once(app_segment))
613611
}
614612

615613
/// Returns an iterator over the OTA segment.
616-
pub fn ota_segments<'b>(self) -> Box<dyn Iterator<Item = Segment<'b>> + 'b>
614+
pub fn ota_segments<'b>(self) -> impl Iterator<Item = Segment<'b>>
617615
where
618616
'a: 'b,
619617
{
620-
Box::new(once(self.flash_segment))
618+
once(self.flash_segment)
621619
}
622620

623621
/// Returns a map of metadata about the application image.

espflash/src/image_format/mod.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,35 +205,33 @@ impl Ord for Segment<'_> {
205205
pub(crate) fn ram_segments<'a>(
206206
chip: Chip,
207207
elf: &'a ElfFile<'a>,
208-
) -> Box<dyn Iterator<Item = Segment<'a>> + 'a> {
209-
Box::new(segments(elf).filter(move |segment| !chip.addr_is_flash(segment.addr)))
208+
) -> impl Iterator<Item = Segment<'a>> {
209+
segments(elf).filter(move |segment| !chip.addr_is_flash(segment.addr))
210210
}
211211

212212
/// Returns an iterator over all ROM segments for a given chip and ELF file.
213213
pub(crate) fn rom_segments<'a>(
214214
chip: Chip,
215215
elf: &'a ElfFile<'a>,
216-
) -> Box<dyn Iterator<Item = Segment<'a>> + 'a> {
217-
Box::new(segments(elf).filter(move |segment| chip.addr_is_flash(segment.addr)))
216+
) -> impl Iterator<Item = Segment<'a>> {
217+
segments(elf).filter(move |segment| chip.addr_is_flash(segment.addr))
218218
}
219219

220-
fn segments<'a>(elf: &'a ElfFile<'a>) -> Box<dyn Iterator<Item = Segment<'a>> + 'a> {
221-
Box::new(
222-
elf.sections()
223-
.filter(|section| {
224-
let header = section.elf_section_header();
225-
226-
section.size() > 0
227-
&& header.sh_type(Endianness::Little) == SHT_PROGBITS
228-
&& header.sh_offset.get(Endianness::Little) > 0
229-
&& section.address() > 0
230-
&& !is_empty(section.flags())
231-
})
232-
.flat_map(move |section| match section.data() {
233-
Ok(data) => Some(Segment::new(section.address() as u32, data)),
234-
_ => None,
235-
}),
236-
)
220+
fn segments<'a>(elf: &'a ElfFile<'a>) -> impl Iterator<Item = Segment<'a>> {
221+
elf.sections()
222+
.filter(|section| {
223+
let header = section.elf_section_header();
224+
225+
section.size() > 0
226+
&& header.sh_type(Endianness::Little) == SHT_PROGBITS
227+
&& header.sh_offset.get(Endianness::Little) > 0
228+
&& section.address() > 0
229+
&& !is_empty(section.flags())
230+
})
231+
.flat_map(move |section| match section.data() {
232+
Ok(data) => Some(Segment::new(section.address() as u32, data)),
233+
_ => None,
234+
})
237235
}
238236

239237
fn is_empty(flags: object::SectionFlags) -> bool {

0 commit comments

Comments
 (0)