Skip to content

Commit 4205ecd

Browse files
authored
Merge pull request #72 from toku-sa-n/hide_iterator_implementation
chore: use `impl Iterator`
2 parents e8856d4 + 12c0310 commit 4205ecd

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/elf_sections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl ElfSectionsTag {
4141
/// }
4242
/// }
4343
/// ```
44-
pub fn sections(&self) -> ElfSectionIter {
44+
pub fn sections(&self) -> impl Iterator<Item = ElfSection> {
4545
let string_section_offset = (self.get().shndx * self.get().entry_size) as isize;
4646
let string_section_ptr =
4747
unsafe { self.first_section().offset(string_section_offset) as *const _ };

src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ pub use elf_sections::{
3131
pub use framebuffer::{FramebufferColor, FramebufferField, FramebufferTag, FramebufferType};
3232
use header::{Tag, TagIter};
3333
pub use memory_map::{
34-
EFIMemoryAreaType, EFIMemoryMapTag, EFIMemoryDesc, MemoryArea, MemoryAreaIter,
35-
MemoryAreaType, MemoryMapTag,
34+
EFIMemoryAreaType, EFIMemoryDesc, EFIMemoryMapTag, MemoryArea, MemoryAreaIter, MemoryAreaType,
35+
MemoryMapTag,
3636
};
3737
pub use module::{ModuleIter, ModuleTag};
3838
pub use rsdp::{
39-
EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64, ImageLoadPhysAddr,
40-
RsdpV1Tag, RsdpV2Tag,
39+
EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64, ImageLoadPhysAddr, RsdpV1Tag, RsdpV2Tag,
4140
};
4241
pub use vbe_info::{
4342
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
@@ -156,7 +155,7 @@ impl BootInformation {
156155
}
157156

158157
/// Get an iterator of all module tags.
159-
pub fn module_tags(&self) -> ModuleIter {
158+
pub fn module_tags(&self) -> impl Iterator<Item = &ModuleTag> {
160159
module::module_iter(self.tags())
161160
}
162161

@@ -207,10 +206,9 @@ impl BootInformation {
207206
// the memory map, as it could still be in use.
208207
match self.get_tag(18) {
209208
Some(_tag) => None,
210-
None => {
211-
self.get_tag(17)
212-
.map(|tag| unsafe { &*(tag as *const Tag as *const EFIMemoryMapTag) })
213-
},
209+
None => self
210+
.get_tag(17)
211+
.map(|tag| unsafe { &*(tag as *const Tag as *const EFIMemoryMapTag) }),
214212
}
215213
}
216214

@@ -1279,9 +1277,9 @@ mod tests {
12791277
1, 0, 0, 0, // EFI descriptor version, don't think this matters.
12801278
7, 0, 0, 0, // Type: EfiConventionalMemory
12811279
0, 0, 0, 0, // Padding
1282-
0, 0, 16, 0,// Physical Address: should be 0x100000
1280+
0, 0, 16, 0, // Physical Address: should be 0x100000
12831281
0, 0, 0, 0, // Extension of physical address.
1284-
0, 0, 16, 0,// Virtual Address: should be 0x100000
1282+
0, 0, 16, 0, // Virtual Address: should be 0x100000
12851283
0, 0, 0, 0, // Extension of virtual address.
12861284
4, 0, 0, 0, // 4 KiB Pages: 16 KiB
12871285
0, 0, 0, 0, // Extension of pages
@@ -1313,9 +1311,9 @@ mod tests {
13131311
1, 0, 0, 0, // EFI descriptor version, don't think this matters.
13141312
7, 0, 0, 0, // Type: EfiConventionalMemory
13151313
0, 0, 0, 0, // Padding
1316-
0, 0, 16, 0,// Physical Address: should be 0x100000
1314+
0, 0, 16, 0, // Physical Address: should be 0x100000
13171315
0, 0, 0, 0, // Extension of physical address.
1318-
0, 0, 16, 0,// Virtual Address: should be 0x100000
1316+
0, 0, 16, 0, // Virtual Address: should be 0x100000
13191317
0, 0, 0, 0, // Extension of virtual address.
13201318
4, 0, 0, 0, // 4 KiB Pages: 16 KiB
13211319
0, 0, 0, 0, // Extension of pages
@@ -1340,5 +1338,4 @@ mod tests {
13401338
core::mem::transmute::<[u8; 56], EFIMemoryMapTag>([0u8; 56]);
13411339
}
13421340
}
1343-
13441341
}

src/memory_map.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl MemoryMapTag {
2727
}
2828

2929
/// Return an iterator over all marked memory areas.
30-
pub fn all_memory_areas(&self) -> MemoryAreaIter {
30+
pub fn all_memory_areas(&self) -> impl Iterator<Item = &MemoryArea> {
3131
let self_ptr = self as *const MemoryMapTag;
3232
let start_area = (&self.first_area) as *const MemoryArea;
3333
MemoryAreaIter {
@@ -111,7 +111,7 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
111111
if self.current_area > self.last_area {
112112
None
113113
} else {
114-
let area = unsafe{&*(self.current_area as *const MemoryArea)};
114+
let area = unsafe { &*(self.current_area as *const MemoryArea) };
115115
self.current_area = self.current_area + (self.entry_size as u64);
116116
Some(area)
117117
}
@@ -260,7 +260,6 @@ pub struct EFIBootServicesNotExited {
260260
size: u32,
261261
}
262262

263-
264263
/// An iterator over ALL EFI memory areas.
265264
#[derive(Clone, Debug)]
266265
pub struct EFIMemoryAreaIter<'a> {
@@ -276,10 +275,9 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
276275
if self.current_area > self.last_area {
277276
None
278277
} else {
279-
let area = unsafe{&*(self.current_area as *const EFIMemoryDesc)};
278+
let area = unsafe { &*(self.current_area as *const EFIMemoryDesc) };
280279
self.current_area = self.current_area + (self.entry_size as u64);
281280
Some(area)
282281
}
283282
}
284283
}
285-

0 commit comments

Comments
 (0)