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

Implement "passthrough" Debug and Display instances for wrappers #858

Merged
merged 3 commits into from
Jul 29, 2024

Conversation

wyager
Copy link
Contributor

@wyager wyager commented Jul 13, 2024

Useful for if you're writing code that switches between defmt::whatever and log::whatever or core::whatever using macros

@jonathanpallant
Copy link
Contributor

Do you have a short example of where this is useful?

@wyager
Copy link
Contributor Author

wyager commented Jul 15, 2024

@jonathanpallant Sure - when writing code that will be used on embedded or desktop, it's pretty common to use a macro adapter like https://github.com/embassy-rs/embassy/blob/ac06ca2fa0aa061a0053336433fa9cbfad5212ca/embassy-sync/src/fmt.rs which switches whatever! between log::whatever! and defmt::whatever!

If the object you are logging is non-defmt (e.g. NorFlashErrorKind), you must wrap it in a Debug2Format to use it with defmt. However, if you do that, now the whatever! macro will fail when you compile for desktop.

This PR fixes that issue. Now, something wrapped in Debug2Format will compile whether using defmt or log as your macro implementation.

@jonathanpallant
Copy link
Contributor

Oh! Right, that makes perfect sense.

@jonathanpallant
Copy link
Contributor

@Urhengulas any thoughts on this one?

Copy link
Member

@Urhengulas Urhengulas left a comment

Choose a reason for hiding this comment

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

Sounds useful to me. Thank you for the contribution @wyager!

@Urhengulas Urhengulas added this pull request to the merge queue Jul 29, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 29, 2024
Implement "passthrough" Debug and Display instances for wrappers
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 29, 2024
@Urhengulas Urhengulas enabled auto-merge July 29, 2024 12:47
@Urhengulas Urhengulas added this pull request to the merge queue Jul 29, 2024
Merged via the queue into knurling-rs:main with commit 6f19880 Jul 29, 2024
16 checks passed
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.

3 participants