-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement core::iter::Step
trait for for PhysFrame
#292
Implement core::iter::Step
trait for for PhysFrame
#292
Conversation
blocked by fix linked in #294 |
@ncatelli can you implement this on EDIT: we've also fixed the CI issue, so you should be able to rebase and have things work |
5e29388
to
9bdd526
Compare
9bdd526
to
644cc68
Compare
These changes have been applied per your request. |
For now I've used an implementation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should implement these in terms of the checked_add/checked_sub implementations. This will result in smaller and more consistent code. Feel free to just have this PR depend on #298
#[cfg(feature = "step_trait")] | ||
impl<S: PageSize> core::iter::Step for PhysFrame<S> { | ||
fn steps_between(start: &Self, end: &Self) -> Option<usize> { | ||
PhysAddr::steps_between(&start.start_address, &end.start_address) | ||
} | ||
|
||
fn forward_checked(start: Self, count: usize) -> Option<Self> { | ||
PhysAddr::forward_checked(start.start_address, count) | ||
.and_then(|start_addr| Self::from_start_address(start_addr).ok()) | ||
} | ||
|
||
fn backward_checked(start: Self, count: usize) -> Option<Self> { | ||
PhysAddr::backward_checked(start.start_address, count) | ||
.and_then(|start_addr| Self::from_start_address(start_addr).ok()) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These implementations are incorrect. We need to be taking the page size into account (so that we are consistent with the PhysFrame<S>: Add<u64>
implementation).
Specifically, steps_between
should be:
end.checked_sub(start)?.try_into()
and forward_checked
should be:
start.checked_add(count.try_into()?)
(similar for backward_checked
)
Oof, that was my mistake, I tried to move it quick to get feedback and didn't think it through. Sorry for the inconvenience. I agree with your above sentiment that it's it should just wait on #293 I'm going to close this out for now and will revisit this after we settle on the implementations for at least the addressing types. |
General
This is an initial naive first pass at implementing
core::iter::Step
forPhysFrame
. I initially had it align off the start address of a frame and look for overflows of theu64
space from the start. But I can imagine it would be worth checking chat the end overflows as well and figured I'd post to get your feedback before deciding.Related Issues
#212