-
Notifications
You must be signed in to change notification settings - Fork 159
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
Move to non-enum Status for type safety reasons #51
Conversation
ca97819
to
73b3844
Compare
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.
Instead of making them constaints in the status
module, what if we just made them associated constants of the Status
type?
pub struct Status ...;
impl Status {
pub const SOME_ERROR: Self = 0;
}
This should greatly reduce the number of changes required.
@GabrielMajeri Cool, did not now you could use that outside of the trait system! Implemented. Now there's only the minor warning question to be resolved and we should be all set. |
(CI failed due to rustfmt) |
In principle, one could build a macro which would reproduce the full enum feeling by using recursion to generate a sequence of numbers from a starting point. However...
|
@HadrienG2 I don't expect to see a lot of status codes being added to the spec anytime soon. The current solution is good. |
As discussed in #48 and #44 before that, it is not safe to use a Rust enum for UEFI status codes due to their open-ended nature. For this reason, this PR proposes to use a newtype of usize and a bunch of constants instead.
A small amount of macromancy is used to reduce the noise and repetition that is inherent to this approach and keep the code readable.
Fixes #48.