@@ -1915,6 +1915,14 @@ impl<'a> MemoryMap for MemoryMapRef<'a> {
19151915 }
19161916}
19171917
1918+ impl Index < usize > for MemoryMapRef < ' _ > {
1919+ type Output = MemoryDescriptor ;
1920+
1921+ fn index ( & self , index : usize ) -> & Self :: Output {
1922+ self . get ( index) . unwrap ( )
1923+ }
1924+ }
1925+
19181926/// Implementation of [`MemoryMapMut`] for the given buffer.
19191927#[ derive( Debug ) ]
19201928pub struct MemoryMapRefMut < ' a > {
@@ -2025,6 +2033,20 @@ impl<'a> MemoryMapRefMut<'a> {
20252033 }
20262034}
20272035
2036+ impl Index < usize > for MemoryMapRefMut < ' _ > {
2037+ type Output = MemoryDescriptor ;
2038+
2039+ fn index ( & self , index : usize ) -> & Self :: Output {
2040+ self . get ( index) . unwrap ( )
2041+ }
2042+ }
2043+
2044+ impl IndexMut < usize > for MemoryMapRefMut < ' _ > {
2045+ fn index_mut ( & mut self , index : usize ) -> & mut Self :: Output {
2046+ self . get_mut ( index) . unwrap ( )
2047+ }
2048+ }
2049+
20282050/// Implementation of [`MemoryMapMut`] that owns the buffer on the UEFI heap.
20292051#[ derive( Debug ) ]
20302052pub struct MemoryMapOwned {
@@ -2105,6 +2127,20 @@ impl MemoryMapMut for MemoryMapOwned {
21052127 }
21062128}
21072129
2130+ impl Index < usize > for MemoryMapOwned {
2131+ type Output = MemoryDescriptor ;
2132+
2133+ fn index ( & self , index : usize ) -> & Self :: Output {
2134+ self . get ( index) . unwrap ( )
2135+ }
2136+ }
2137+
2138+ impl IndexMut < usize > for MemoryMapOwned {
2139+ fn index_mut ( & mut self , index : usize ) -> & mut Self :: Output {
2140+ self . get_mut ( index) . unwrap ( )
2141+ }
2142+ }
2143+
21082144/// An iterator of [`MemoryDescriptor`]. The underlying memory map is always
21092145/// associated with a unique [`MemoryMapKey`].
21102146#[ derive( Debug , Clone ) ]
@@ -2349,7 +2385,10 @@ mod tests_mmap_artificial {
23492385 let mut mem_map = buffer_to_map ( & mut buffer) ;
23502386
23512387 for index in 0 ..3 {
2352- assert_eq ! ( mem_map. get( index) , BUFFER . get( index) )
2388+ assert_eq ! ( mem_map. get( index) , BUFFER . get( index) ) ;
2389+
2390+ // Test Index impl
2391+ assert_eq ! ( Some ( & mem_map[ index] ) , BUFFER . get( index) ) ;
23532392 }
23542393
23552394 let mut_desc = mem_map. get_mut ( 2 ) . unwrap ( ) ;
0 commit comments