@@ -23,9 +23,15 @@ pub struct MemoryMapTag {
23
23
impl MemoryMapTag {
24
24
/// Return an iterator over all AVAILABLE marked memory areas.
25
25
pub fn memory_areas ( & self ) -> MemoryAreaIter {
26
+ MemoryAreaIter {
27
+ iter : self . all_memory_areas ( ) ;
28
+ }
29
+ }
30
+ /// Return an iterator over all marked memory areas.
31
+ pub fn all_memory_areas ( & self ) -> AllMemoryAreaIter {
26
32
let self_ptr = self as * const MemoryMapTag ;
27
33
let start_area = ( & self . first_area ) as * const MemoryArea ;
28
- MemoryAreaIter {
34
+ AllMemoryAreaIter {
29
35
current_area : start_area as u64 ,
30
36
last_area : ( self_ptr as u64 + ( self . size - self . entry_size ) as u64 ) ,
31
37
entry_size : self . entry_size ,
@@ -91,26 +97,42 @@ pub enum MemoryAreaType {
91
97
Defective ,
92
98
}
93
99
94
- /// An iterator over Available memory areas.
100
+ /// An iterator over all memory areas
95
101
#[ derive( Clone , Debug ) ]
96
- pub struct MemoryAreaIter < ' a > {
102
+ pub struct AllMemoryAreaIter < ' a > {
97
103
current_area : u64 ,
98
104
last_area : u64 ,
99
105
entry_size : u32 ,
100
106
phantom : PhantomData < & ' a MemoryArea > ,
101
107
}
102
108
103
- impl < ' a > Iterator for MemoryAreaIter < ' a > {
109
+ impl < ' a > Iterator for AllMemoryAreaIter < ' a > {
104
110
type Item = & ' a MemoryArea ;
105
111
fn next ( & mut self ) -> Option < & ' a MemoryArea > {
106
112
if self . current_area > self . last_area {
107
113
None
108
114
} else {
109
115
let area = unsafe { & * ( self . current_area as * const MemoryArea ) } ;
110
116
self . current_area = self . current_area + ( self . entry_size as u64 ) ;
111
- if area. typ == 1 {
112
- Some ( area)
113
- } else { self . next ( ) }
117
+ Some ( area)
118
+ }
119
+ }
120
+ }
121
+
122
+ /// An iterator over Available memory areas.
123
+ #[ derive( Clone , Debug ) ]
124
+ pub struct MemoryAreaIter < ' a > {
125
+ iter : AllMemoryAreaIter < ' a > ,
126
+ }
127
+
128
+ impl < ' a > Iterator for MemoryAreaIter < ' a > {
129
+ type Item = & ' a MemoryArea ;
130
+ fn next ( & mut self ) -> Option < & ' a MemoryArea > {
131
+ let ret = self . iter . next ( ) ?;
132
+ if ret. typ == 1 {
133
+ Some ( ret)
134
+ } else {
135
+ self . next ( )
114
136
}
115
137
}
116
138
}
0 commit comments