@@ -4,6 +4,8 @@ use crate::structures::paging::page_table::PageTableLevel;
4
4
use crate :: structures:: paging:: PageTableIndex ;
5
5
use crate :: VirtAddr ;
6
6
use core:: fmt;
7
+ #[ cfg( feature = "step_trait" ) ]
8
+ use core:: iter:: Step ;
7
9
use core:: marker:: PhantomData ;
8
10
use core:: ops:: { Add , AddAssign , Sub , SubAssign } ;
9
11
@@ -274,6 +276,32 @@ impl<S: PageSize> Sub<Self> for Page<S> {
274
276
}
275
277
}
276
278
279
+ #[ cfg( feature = "step_trait" ) ]
280
+ impl < S : PageSize > Step for Page < S > {
281
+ fn steps_between ( start : & Self , end : & Self ) -> Option < usize > {
282
+ Step :: steps_between ( & start. start_address , & end. start_address )
283
+ . map ( |steps| steps / S :: SIZE as usize )
284
+ }
285
+
286
+ fn forward_checked ( start : Self , count : usize ) -> Option < Self > {
287
+ let count = count. checked_mul ( S :: SIZE as usize ) ?;
288
+ let start_address = Step :: forward_checked ( start. start_address , count) ?;
289
+ Some ( Self {
290
+ start_address,
291
+ size : PhantomData ,
292
+ } )
293
+ }
294
+
295
+ fn backward_checked ( start : Self , count : usize ) -> Option < Self > {
296
+ let count = count. checked_mul ( S :: SIZE as usize ) ?;
297
+ let start_address = Step :: backward_checked ( start. start_address , count) ?;
298
+ Some ( Self {
299
+ start_address,
300
+ size : PhantomData ,
301
+ } )
302
+ }
303
+ }
304
+
277
305
/// A range of pages with exclusive upper bound.
278
306
#[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
279
307
#[ repr( C ) ]
0 commit comments