File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1
1
//! Abstractions for page tables and page table entries.
2
2
3
3
use core:: fmt;
4
+ #[ cfg( feature = "step_trait" ) ]
5
+ use core:: iter:: Step ;
4
6
use core:: ops:: { Index , IndexMut } ;
5
7
6
8
use super :: { PageSize , PhysFrame , Size4KiB } ;
@@ -341,6 +343,26 @@ impl From<PageTableIndex> for usize {
341
343
}
342
344
}
343
345
346
+ #[ cfg( feature = "step_trait" ) ]
347
+ impl Step for PageTableIndex {
348
+ #[ inline]
349
+ fn steps_between ( start : & Self , end : & Self ) -> Option < usize > {
350
+ end. 0 . checked_sub ( start. 0 ) . map ( usize:: from)
351
+ }
352
+
353
+ #[ inline]
354
+ fn forward_checked ( start : Self , count : usize ) -> Option < Self > {
355
+ let idx = usize:: from ( start) . checked_add ( count) ?;
356
+ ( idx < ENTRY_COUNT ) . then ( || Self :: new ( idx as u16 ) )
357
+ }
358
+
359
+ #[ inline]
360
+ fn backward_checked ( start : Self , count : usize ) -> Option < Self > {
361
+ let idx = usize:: from ( start) . checked_sub ( count) ?;
362
+ Some ( Self :: new ( idx as u16 ) )
363
+ }
364
+ }
365
+
344
366
/// A 12-bit offset into a 4KiB Page.
345
367
///
346
368
/// This type is returned by the `VirtAddr::page_offset` method.
You can’t perform that action at this time.
0 commit comments