interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi / src / mem / memory_map / iter.rs

38 lines · 917 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use super::*;
4
5/// An iterator for [`MemoryMap`].
6///
7/// The underlying memory might contain an invalid/malformed memory map
8/// which can't be checked during construction of this type. The iterator
9/// might yield unexpected results.
10#[derive(Debug, Clone)]
11pub struct MemoryMapIter<'a> {
12 pub(crate) memory_map: &'a dyn MemoryMap,
13 pub(crate) index: usize,
14}
15
16impl<'a> Iterator for MemoryMapIter<'a> {
17 type Item = &'a MemoryDescriptor;
18
19 fn next(&mut self) -> Option<Self::Item> {
20 let desc = self.memory_map.get(self.index)?;
21
22 self.index += 1;
23
24 Some(desc)
25 }
26
27 fn size_hint(&self) -> (usize, Option<usize>) {
28 let sz = self.memory_map.len() - self.index;
29
30 (sz, Some(sz))
31 }
32}
33
34impl ExactSizeIterator for MemoryMapIter<'_> {
35 fn len(&self) -> usize {
36 self.memory_map.len() - self.index
37 }
38}