-
Notifications
You must be signed in to change notification settings - Fork 747
make TakeCell::empty() const, and make nrf52840 GPIO pin initialization a const fn #3937
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
because of lifetimes the initialization cannot (yet) happen in a const
This trick has actually worked for a long time (apparently, since 1.32 https://godbolt.org/z/5bWhYf5fP), but only because the const is defined as an associated constant. The mutable reference in a const error is triggered when you put the const elsewhere (e.g. in the body of |
Bringing to the attention of @lschuermann |
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.
One comment, otherwise looks good
7d201e7
to
d888b8b
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.
Sorry for my late response; this looks good to me. I was pretty sure that this would still allow creation of trait objects due to this associated const not being part of the trait, but wanted to double check. This still works, so we won't run into any issues in the future here!
Pull Request Overview
This pull request makes the
TakeCell::new
function const. This requires an associated constant: moving the constant intofn new
does not work, not using an explicit constant also does not work.That function being const can then be used to initialize the gpio pins for the ntrf52840 in a
const fn
. It can't happen in an actual const because the final type contains a (non-static) lifetime.There are many more functions that can now become a
const fn
: I can add some to this PR but those are scattered all around the codebase.Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.