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

Decode breaks when conditionally using write! #455

Closed
Dirbaio opened this issue Apr 21, 2021 · 1 comment
Closed

Decode breaks when conditionally using write! #455

Dirbaio opened this issue Apr 21, 2021 · 1 comment
Labels
difficulty: hard Fairly difficult to solve priority: high High priority for the Knurling team status: needs design This feature needs design work to move forward type: bug Something isn't working

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Apr 21, 2021

    enum OneOrTwo {
        One(u32),
        Two((u32, u32)),
    }

    impl defmt::Format for OneOrTwo {
        fn format(&self, fmt: Formatter) {
            match self {
                Self::One(x) => defmt::write!(fmt, "{=u32}", x),
                Self::Two((x, y)) => defmt::write!(fmt, "{=u32}-{=u32}", x, y),
            }
        }
    }

    let mix = [OneOrTwo::One(1), OneOrTwo::Two((2, 3))];
    defmt::info!("boom: {=[?]}", &mix[..]);

prints

 INFO  boom: [1, 2]
└─ spam::run_test::{{impl}}::format @ /home/dirbaio/nanofmt/fw/src/bin/spam.rs:51
(HOST) ERROR failed to decode defmt data: [3, 0, 0, 0, 28, 1, 0, 0, ... etc

This happens because slices omit the format tag for all but the first item assuming they're equal. With custom Format impls they're not necessarily equal.

@Dirbaio Dirbaio changed the title Decode breaks when conditionally using `write! Decode breaks when conditionally using write! Apr 21, 2021
@jonas-schievink jonas-schievink added priority: high High priority for the Knurling team type: bug Something isn't working labels Apr 22, 2021
@jonas-schievink jonas-schievink added difficulty: medium Somewhat difficult to solve status: needs design This feature needs design work to move forward difficulty: hard Fairly difficult to solve and removed difficulty: medium Somewhat difficult to solve labels May 5, 2021
@japaric
Copy link
Member

japaric commented Jul 7, 2021

this appears to already have been fixed in the main branch (possibly by #508)

@japaric japaric closed this as completed Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: hard Fairly difficult to solve priority: high High priority for the Knurling team status: needs design This feature needs design work to move forward type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants