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

Suggestion: add #[defmt(transparent)] attribute to Format derive #934

Open
vic1707 opened this issue Feb 10, 2025 · 0 comments · May be fixed by #937
Open

Suggestion: add #[defmt(transparent)] attribute to Format derive #934

vic1707 opened this issue Feb 10, 2025 · 0 comments · May be fixed by #937

Comments

@vic1707
Copy link

vic1707 commented Feb 10, 2025

reading the doc

Newtypes
If you need to implement Format for some "newtype" struct you can delegate the formatting to the inner type.
Example below:

struct MyU8 { inner: u8 }

impl defmt::Format for MyU8 {
    fn format(&self, f: defmt::Formatter) {
       self.inner.format(f)
    }
}

I wonder if doing (on structs with one field only)

#[derive(defmt::Format)]
#[defmt(transparent)]
struct MyU8(u8);

wouldn't be nice for users 🤔.

A nice touch would be to also allow it on enums

#[derive(defmt::Format)]
#[defmt(transparent)]
enum MyEnum {
    U8(u8),
    MyPayload(MyPayload),
}
@vic1707 vic1707 linked a pull request Feb 14, 2025 that will close this issue
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 a pull request may close this issue.

1 participant