Skip to content

chore: use impl Iterator #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/elf_sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ElfSectionsTag {
/// }
/// }
/// ```
pub fn sections(&self) -> ElfSectionIter {
pub fn sections(&self) -> impl Iterator<Item = ElfSection> {
let string_section_offset = (self.get().shndx * self.get().entry_size) as isize;
let string_section_ptr =
unsafe { self.first_section().offset(string_section_offset) as *const _ };
Expand Down
25 changes: 11 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ pub use elf_sections::{
pub use framebuffer::{FramebufferColor, FramebufferField, FramebufferTag, FramebufferType};
use header::{Tag, TagIter};
pub use memory_map::{
EFIMemoryAreaType, EFIMemoryMapTag, EFIMemoryDesc, MemoryArea, MemoryAreaIter,
MemoryAreaType, MemoryMapTag,
EFIMemoryAreaType, EFIMemoryDesc, EFIMemoryMapTag, MemoryArea, MemoryAreaIter, MemoryAreaType,
MemoryMapTag,
};
pub use module::{ModuleIter, ModuleTag};
pub use rsdp::{
EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64, ImageLoadPhysAddr,
RsdpV1Tag, RsdpV2Tag,
EFIImageHandle32, EFIImageHandle64, EFISdt32, EFISdt64, ImageLoadPhysAddr, RsdpV1Tag, RsdpV2Tag,
};
pub use vbe_info::{
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
Expand Down Expand Up @@ -156,7 +155,7 @@ impl BootInformation {
}

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

Expand Down Expand Up @@ -207,10 +206,9 @@ impl BootInformation {
// the memory map, as it could still be in use.
match self.get_tag(18) {
Some(_tag) => None,
None => {
self.get_tag(17)
.map(|tag| unsafe { &*(tag as *const Tag as *const EFIMemoryMapTag) })
},
None => self
.get_tag(17)
.map(|tag| unsafe { &*(tag as *const Tag as *const EFIMemoryMapTag) }),
}
}

Expand Down Expand Up @@ -1279,9 +1277,9 @@ mod tests {
1, 0, 0, 0, // EFI descriptor version, don't think this matters.
7, 0, 0, 0, // Type: EfiConventionalMemory
0, 0, 0, 0, // Padding
0, 0, 16, 0,// Physical Address: should be 0x100000
0, 0, 16, 0, // Physical Address: should be 0x100000
0, 0, 0, 0, // Extension of physical address.
0, 0, 16, 0,// Virtual Address: should be 0x100000
0, 0, 16, 0, // Virtual Address: should be 0x100000
0, 0, 0, 0, // Extension of virtual address.
4, 0, 0, 0, // 4 KiB Pages: 16 KiB
0, 0, 0, 0, // Extension of pages
Expand Down Expand Up @@ -1313,9 +1311,9 @@ mod tests {
1, 0, 0, 0, // EFI descriptor version, don't think this matters.
7, 0, 0, 0, // Type: EfiConventionalMemory
0, 0, 0, 0, // Padding
0, 0, 16, 0,// Physical Address: should be 0x100000
0, 0, 16, 0, // Physical Address: should be 0x100000
0, 0, 0, 0, // Extension of physical address.
0, 0, 16, 0,// Virtual Address: should be 0x100000
0, 0, 16, 0, // Virtual Address: should be 0x100000
0, 0, 0, 0, // Extension of virtual address.
4, 0, 0, 0, // 4 KiB Pages: 16 KiB
0, 0, 0, 0, // Extension of pages
Expand All @@ -1340,5 +1338,4 @@ mod tests {
core::mem::transmute::<[u8; 56], EFIMemoryMapTag>([0u8; 56]);
}
}

}
8 changes: 3 additions & 5 deletions src/memory_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl MemoryMapTag {
}

/// Return an iterator over all marked memory areas.
pub fn all_memory_areas(&self) -> MemoryAreaIter {
pub fn all_memory_areas(&self) -> impl Iterator<Item = &MemoryArea> {
let self_ptr = self as *const MemoryMapTag;
let start_area = (&self.first_area) as *const MemoryArea;
MemoryAreaIter {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
if self.current_area > self.last_area {
None
} else {
let area = unsafe{&*(self.current_area as *const MemoryArea)};
let area = unsafe { &*(self.current_area as *const MemoryArea) };
self.current_area = self.current_area + (self.entry_size as u64);
Some(area)
}
Expand Down Expand Up @@ -260,7 +260,6 @@ pub struct EFIBootServicesNotExited {
size: u32,
}


/// An iterator over ALL EFI memory areas.
#[derive(Clone, Debug)]
pub struct EFIMemoryAreaIter<'a> {
Expand All @@ -276,10 +275,9 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
if self.current_area > self.last_area {
None
} else {
let area = unsafe{&*(self.current_area as *const EFIMemoryDesc)};
let area = unsafe { &*(self.current_area as *const EFIMemoryDesc) };
self.current_area = self.current_area + (self.entry_size as u64);
Some(area)
}
}
}