-
-
Notifications
You must be signed in to change notification settings - Fork 770
Process trait improvements #3716
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
Conversation
/// Header, returns 0. | ||
fn binary_version(&self) -> u32; | ||
/// in a TBF Program Header; if the binary has no version assigned, return [None] | ||
fn binary_version(&self) -> Option<BinaryVersion>; |
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.
Previously, 0 marked the absence of the binary version. This approach works, but Option
is the Rust way of doing this in my opinion.
Using a u32
for the binary version is too powerful: several operations defined on the integer type don't make sense, like addition or division. Or do they?
In the end, NonZeroU32 has been chosen as the underlying type of the new BinaryVersion
type. This allows code generation optimizations. In my tests, the new version compiles exactly the same to the old code.
size: usize, | ||
align: usize, | ||
) -> bool; | ||
) -> Result<(), ()>; |
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.
Result
is the Rust way of signaling a function may fail. Additionally, Result
triggers a warning when the return value is unused. From my little experiments, the new signature is compiled to the same code as the old one.
size: usize, | ||
align: usize, | ||
) -> Option<(ProcessCustomGrantIdentifier, NonNull<u8>)>; | ||
) -> Result<(ProcessCustomGrantIdentifier, NonNull<u8>), ()>; |
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.
This follows the pattern of returning a Result
as allocate_grant
.
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 like this change.
Pull Request Overview
This pull request brings little improvements to the
Process
trait.Testing Strategy
This pull request was tested by running
libtock-c
applications on STM32F429ZI Nucleo-144.TODO or Help Wanted
No help needed.
Documentation Updated
Formatting
make prepush
.