@@ -1921,6 +1921,14 @@ impl<'a> MemoryMap for MemoryMapRef<'a> {
1921
1921
}
1922
1922
}
1923
1923
1924
+ impl Index < usize > for MemoryMapRef < ' _ > {
1925
+ type Output = MemoryDescriptor ;
1926
+
1927
+ fn index ( & self , index : usize ) -> & Self :: Output {
1928
+ self . get ( index) . unwrap ( )
1929
+ }
1930
+ }
1931
+
1924
1932
/// Implementation of [`MemoryMapMut`] for the given buffer.
1925
1933
#[ derive( Debug ) ]
1926
1934
pub struct MemoryMapRefMut < ' a > {
@@ -2031,6 +2039,20 @@ impl<'a> MemoryMapRefMut<'a> {
2031
2039
}
2032
2040
}
2033
2041
2042
+ impl Index < usize > for MemoryMapRefMut < ' _ > {
2043
+ type Output = MemoryDescriptor ;
2044
+
2045
+ fn index ( & self , index : usize ) -> & Self :: Output {
2046
+ self . get ( index) . unwrap ( )
2047
+ }
2048
+ }
2049
+
2050
+ impl IndexMut < usize > for MemoryMapRefMut < ' _ > {
2051
+ fn index_mut ( & mut self , index : usize ) -> & mut Self :: Output {
2052
+ self . get_mut ( index) . unwrap ( )
2053
+ }
2054
+ }
2055
+
2034
2056
/// Implementation of [`MemoryMapMut`] that owns the buffer on the UEFI heap.
2035
2057
#[ derive( Debug ) ]
2036
2058
pub struct MemoryMapOwned {
@@ -2111,6 +2133,20 @@ impl MemoryMapMut for MemoryMapOwned {
2111
2133
}
2112
2134
}
2113
2135
2136
+ impl Index < usize > for MemoryMapOwned {
2137
+ type Output = MemoryDescriptor ;
2138
+
2139
+ fn index ( & self , index : usize ) -> & Self :: Output {
2140
+ self . get ( index) . unwrap ( )
2141
+ }
2142
+ }
2143
+
2144
+ impl IndexMut < usize > for MemoryMapOwned {
2145
+ fn index_mut ( & mut self , index : usize ) -> & mut Self :: Output {
2146
+ self . get_mut ( index) . unwrap ( )
2147
+ }
2148
+ }
2149
+
2114
2150
/// An iterator of [`MemoryDescriptor`]. The underlying memory map is always
2115
2151
/// associated with a unique [`MemoryMapKey`].
2116
2152
#[ derive( Debug , Clone ) ]
@@ -2355,7 +2391,10 @@ mod tests_mmap_artificial {
2355
2391
let mut mem_map = buffer_to_map ( & mut buffer) ;
2356
2392
2357
2393
for index in 0 ..3 {
2358
- assert_eq ! ( mem_map. get( index) , BUFFER . get( index) )
2394
+ assert_eq ! ( mem_map. get( index) , BUFFER . get( index) ) ;
2395
+
2396
+ // Test Index impl
2397
+ assert_eq ! ( Some ( & mem_map[ index] ) , BUFFER . get( index) ) ;
2359
2398
}
2360
2399
2361
2400
let mut_desc = mem_map. get_mut ( 2 ) . unwrap ( ) ;
0 commit comments