Introduce BOARD const, deprecating board() function#34
Conversation
|
That was ... faster than expected: rust-lang/rust#107429 makes this possible once 1.69 is stable (less than 12 weeks from now). |
| /// force the compiler to remove all the exceptions at build time (currently it does not, even with | ||
| /// aggressive optimization). | ||
| #[deprecated(note = "Access BOARD instead")] | ||
| pub fn board() -> &'static str { |
There was a problem hiding this comment.
Alternatively this can be pub const fn board() ... and pub const BOARD: &str = board();.
There was a problem hiding this comment.
Right -- making it a const fn would really do just the same, especially when going with a const. (There'd be some difference when using a static, but I'd hope that the compiler stores a string valued const only once anyway if it detects multiple use).
Either way, the stabilization is nigh, 10 weeks to go :-)
There was a problem hiding this comment.
(Sorry for double-posting if this eventually does get through; I've written this already once and GitHub seems to have swallowed it).
I've tried this out on 1.72, and observed that unless forced at the user site through a local const (or using the feature inline_const), the exception only occurs at run time. That's probably fine from an execution model PoV (i.e., not a bug in Rust), but undesirable in our situation (eventually I hope to avoid all UTF-8 wellformedness checks in built code, but even if we can't get that, at least I don't want the error messages in my binaries). So I'd like to stick with having defining it in the const, and making board() -- indeed now a const fn -- return that value.
This is migrating over a PR that was previously discussed at https://gitlab.com/etonomy/riot-wrappers/-/merge_requests/2
Current status is that core::ffi::CStr::from_bytes_with_nul becomes stably const. This is tracked at rust-lang/rust#101719, which I understand to make best progress by letting it sit undisturbed long enough for a FCP to be started.
(The branch itself it a tad old, it might be easier to just have a do-over once that FCP is through).