-
Notifications
You must be signed in to change notification settings - Fork 194
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
small usability issue with esp_hal::init()
#2086
Comments
This is completely intentional. If we're going to introduce new options, we don't want to break existing code. The style I prefer is: let peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
config.cpu_clock = CpuClock::max();
config
}); Or I think you should be able to do something like: let peripherals = esp_hal::init(esp_hal::Config {
cpu_clock: CpuClock::max(),
..Default::default()
}); |
or something like this maybe? let peripherals = esp_hal::init(esp_hal::Config::default()
.with_cpu_clock(CpuClock::max()));
}); The rust error told you to "look for a new() method" or something like that. |
Of the two you posed I prefer ^^ |
Builders are fine I guess, but unless there's extreme interest for them, I'd love to avoid adding more code for a single use struct :( |
IMHO the |
As @bugadani mentioned, this is by design so we can add fields and not break code in the future. Imo |
That does not seem to work:
|
Ah, you're right. I'm hoping it's something that will be allowed in the future. It currently only works on structs defined within the crate, see: https://rust-lang.github.io/rfcs/2008-non-exhaustive.html#functional-record-updates. In which case, @bugadani's first option works and it's not too much more code. I personally don't see the advantage of a builder pattern, but I'm open to hear other options. |
That's sad, but hopefully it's still not the end of the world. Again, we have to balance stability, lines of code (yes, really!) and useability and I think we're in a local maximum of the 3. |
If you want to set the clock you can't do:
because it's marked with
#[non_exhaustive]
one must go this route:The text was updated successfully, but these errors were encountered: