esp-rs / espflash

Serial flasher utility for Espressif SoCs and modules based on esptool.py
Apache License 2.0
455 stars 110 forks source link

API improvements #512

Closed SergioGasquez closed 6 months ago

SergioGasquez commented 7 months ago

Not completely convinced on the FlashData name.

jessebraham commented 7 months ago

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 commented 7 months ago

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

SergioGasquez commented 6 months ago

Rebased on top of https://github.com/esp-rs/espflash/pull/525! Clippy is now screaming louder that a function has too many args (9/7)

bugadani commented 5 months ago

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.