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

Derive common traits for various types in uart and i2c drivers #2825

Merged
merged 5 commits into from
Dec 19, 2024

Conversation

jessebraham
Copy link
Member

@jessebraham jessebraham commented Dec 17, 2024

Some notes related to the traits mentioned in the corresponding issues:

Regarding the implementation of Display:

  • i2c::master::ConfigError has no variants, so implementing Display is meaningless for it (i.e. what would we actually display?)
    • Regardless, can derive strum::Display on this type if requested
  • What should Display look like for i2c::master::Config
  • What should Display look like for i2c::master::I2c

Happy to make the Display-related changes, just would like to come to a consensus with regards to how this should look so we can be consistent across drivers.

Closes #2776
Closes #2810
Closes #2788

@bugadani
Copy link
Contributor

fugit::Rate does not implement Hash, so i2c::master::Config cannot derive it

I opted to manually implement it like https://github.com/esp-rs/esp-hal/pull/2823/files#diff-f2b53d5313d6241262548c66be719b207cf49feadd833841f499ed4afdf1dfe2R441 . What do you think about that?

@SergioGasquez
Copy link
Member

This PR also closes #2788, as it implements Debug for Info and Operation which is what I had in mind.

@jessebraham jessebraham force-pushed the fixes/c-common-traits branch 2 times, most recently from 2e93fec to 79df783 Compare December 18, 2024 08:38
@jessebraham jessebraham force-pushed the fixes/c-common-traits branch from 79df783 to 1a1bfe7 Compare December 19, 2024 08:54

impl core::fmt::Display for ConfigError {
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Ok(())
Copy link
Member Author

Choose a reason for hiding this comment

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

This looks a little insane, but #2831 will add some variants and so once this is merged, it can be rebased on top of these changes and a proper implementation can be added for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would strum::Display make sense here, as well?

@jessebraham
Copy link
Member Author

Error and Display implementations have been added for error types, should be good to go now.

@jessebraham jessebraham force-pushed the fixes/c-common-traits branch from 1a1bfe7 to 211c38b Compare December 19, 2024 09:03
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::ExceedingFifo => write!(f, "The transmission exceeded the FIFO size"),
Copy link
Contributor

Choose a reason for hiding this comment

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

There are crates that can turn docstrings into Display output (displaydoc or docsplay). Should we try and use them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess thiserror does support no_std now, but I'm fairly indifferent.

Copy link
Contributor

@JurajSadel JurajSadel left a comment

Choose a reason for hiding this comment

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

Thanks!

@JurajSadel JurajSadel added this pull request to the merge queue Dec 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 19, 2024
@jessebraham jessebraham force-pushed the fixes/c-common-traits branch from 211c38b to 3fb4ec0 Compare December 19, 2024 09:55
@jessebraham jessebraham added this pull request to the merge queue Dec 19, 2024
Merged via the queue into esp-rs:main with commit 1fff464 Dec 19, 2024
28 checks passed
@jessebraham jessebraham deleted the fixes/c-common-traits branch December 19, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants