Skip to content
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

API improvements #512

Merged
merged 6 commits into from
Jan 9, 2024
Merged

Conversation

SergioGasquez
Copy link
Member

  • Created non_exhaustinve FlashData and FlashSettings structs to reduce number of input arguments in the following functions:
    • save_elf_as_image
    • flash_elf_image
    • load_elf_to_flash
    • get_flash_image for all targets
  • Using FlashData avoids duplicating code of parsing the bootloader and partition table file that was present in several places.

Not completely convinced on the FlashData name.

@SergioGasquez SergioGasquez linked an issue Nov 17, 2023 that may be closed by this pull request
2 tasks
@jessebraham
Copy link
Member

Thanks for taking care of this! I took a quick look and I think it looks pretty good overall, but I have a couple features I'd like to continue developing to see how they affect this.

Will try to get this taken care of sooner than later and update here when able.

@SergioGasquez
Copy link
Member Author

Rebased on top of #516! But now Clippy is back at screaming that a function has too many args (8/7) :(

@SergioGasquez
Copy link
Member Author

Rebased on top of #525! Clippy is now screaming louder that a function has too many args (9/7)

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to review this, but I think it's looking pretty good. Thanks again for taking care of this.

We should still do another review of the public API before the release, but no point holding things up any longer here.

@jessebraham jessebraham merged commit 3d91a9b into esp-rs:main Jan 9, 2024
19 checks passed
@SergioGasquez SergioGasquez deleted the feature/api-improvements branch January 9, 2024 15:25
@bugadani
Copy link
Contributor

bugadani commented Jan 30, 2024

I've spent a few minuted touching the related code in probe-rs, here are my initial impressions:

I find #[non_exhaustive] structs with all-public fields somewhat weird if I don't have a shorthand to create them. If I have to basically list all fields while calling new, it's just a worse version of non-#[non_exhaustive]. That FlashData does some actual login in its new somewhat mitigates this point, but:

I think a builder for FlashData would help greatly in its usability. Many optional parameters in new doesn't really help usability compared to the previous state. If the API looked like Builder::new(required_params).with_optional_x(x).with_optional_y(y).build() there would be no question of what the individual None-s mean and which order they come in.

Also I find it somewhat weird that I have to specify a chip revision for FlashData, then I need a minimum revision (a pair, which is... unclear from the signature) in get_flash_image.

FlashData::new() also does not return espflash::error::Error. I'm not yet sure if espflash::error::Error was split up or changed further, but if not, then this fact complicates error handling a bit. miettealso does not recommend Report:

It’s a best practice to wrap any “external” error types in your error enum instead of using something like Report in a library.

This was referenced Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Public API needs improvements to make it more extensible
3 participants