-
Notifications
You must be signed in to change notification settings - Fork 133
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
Make align_up and align_down const #270
Conversation
Shouldn't these functions take (and return) |
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.
Looks good to me overall. Nice trick with the [(); 1]
array!
One thing that is a bit unfortunate is that users on stable will get a meaningless "index out of bounds" error if they supply a non-aligned aligment. I don't think that there is any way to avoid this right now, but we should at least document this error in the method docs, e.g. as:
Panics if the alignment is not a power of two. Without the
const_fn
feature, the panic message will be an "index out of bounds" error in that case.
Additionally, we could add line comments before the [(); 1][!align.is_power_of_two() as usize]
lines that say something like "if a panic occurs at this line it means that align
was not a power of two". This way, users that look up the panic origin in the source directly see the reason for it.
They could, but there are other places in this crate where Lines 68 to 74 in e5c202c
Since conversions between u64 and usize are not really convenient ( |
We can't make VirtAddr and PhysAddr methods const as they wrap an into impl.
Signed-off-by: Joe Richey <[email protected]>
Signed-off-by: Joe Richey <[email protected]>
Signed-off-by: Joe Richey <[email protected]>
Docs updated (along with the GDT push method).
Instead of this I just added a |
Good solution, thanks a lot! |
We can't make the
{VirtAddr, PhysAddr}::{align_up, align_down, is_aligned}
methods const as they have aU: Into<u64>
constraint.We should consider removing this constraint for the next breaking change.