Skip to content

Commit

Permalink
multiboot2: Combine EFIMemoryAreaIter(Mut)
Browse files Browse the repository at this point in the history
  • Loading branch information
YtvwlD committed Jul 9, 2023
1 parent 52406a0 commit 06732b3
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions multiboot2/src/memory_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl EFIMemoryMapTag {
///
/// This differs from `MemoryMapTag` as for UEFI, the OS needs some non-
/// available memory areas for tables and such.
pub fn memory_areas(&self) -> EFIMemoryAreaIter {
pub fn memory_areas(&self) -> EFIMemoryAreaIter<&EFIMemoryDesc> {
let self_ptr = self as *const EFIMemoryMapTag;
let start_area = (&self.descs[0]) as *const EFIMemoryDesc;
EFIMemoryAreaIter {
Expand All @@ -259,10 +259,10 @@ impl EFIMemoryMapTag {
///
/// This differs from `MemoryMapTag` as for UEFI, the OS needs some non-
/// available memory areas for tables and such.
pub fn memory_areas_mut(&mut self) -> EFIMemoryAreaIterMut {
pub fn memory_areas_mut(&mut self) -> EFIMemoryAreaIter<&mut EFIMemoryDesc> {
let self_ptr = self as *mut EFIMemoryMapTag;
let start_area = (&mut self.descs[0]) as *mut EFIMemoryDesc;
EFIMemoryAreaIterMut {
EFIMemoryAreaIter {
current_area: start_area as u64,
// NOTE: `last_area` is only a bound, it doesn't necessarily point exactly to the last element
last_area: (self_ptr as *mut () as u64 + self.size as u64),
Expand Down Expand Up @@ -329,14 +329,14 @@ impl StructAsBytes for EFIBootServicesNotExitedTag {

/// An iterator over ALL EFI memory areas.
#[derive(Clone, Debug)]
pub struct EFIMemoryAreaIter<'a> {
pub struct EFIMemoryAreaIter<T> {
current_area: u64,
last_area: u64,
entry_size: u32,
phantom: PhantomData<&'a EFIMemoryDesc>,
phantom: PhantomData<T>,
}

impl<'a> Iterator for EFIMemoryAreaIter<'a> {
impl<'a> Iterator for EFIMemoryAreaIter<&'a EFIMemoryDesc> {
type Item = &'a EFIMemoryDesc;
fn next(&mut self) -> Option<&'a EFIMemoryDesc> {
if self.current_area > self.last_area {
Expand All @@ -349,16 +349,7 @@ impl<'a> Iterator for EFIMemoryAreaIter<'a> {
}
}

/// An iterator over ALL EFI memory areas, mutably.
#[derive(Clone, Debug)]
pub struct EFIMemoryAreaIterMut<'a> {
current_area: u64,
last_area: u64,
entry_size: u32,
phantom: PhantomData<&'a mut EFIMemoryDesc>,
}

impl<'a> Iterator for EFIMemoryAreaIterMut<'a> {
impl<'a> Iterator for EFIMemoryAreaIter<&'a mut EFIMemoryDesc> {
type Item = &'a mut EFIMemoryDesc;
fn next(&mut self) -> Option<&'a mut EFIMemoryDesc> {
if self.current_area > self.last_area {
Expand Down

0 comments on commit 06732b3

Please sign in to comment.