defmt icon indicating copy to clipboard operation
defmt copied to clipboard

No way to print an hex byte slice compatible with both defmt+log

Open Dirbaio opened this issue 4 years ago • 0 comments

I'm using a set of macros to forward log calls to defmt or log based on Cargo features, to make code portable between embedded and std platforms.

I can't find a way to print a hex byte slice that works both in defmt and log:

    let id: &[u8] = [0x12, 0x34, 0x56, 0x78];

    // defmt fails with `unknown display hint: "02x?"`
    info!("card id = {:02x?}", id);

    // log fails with `the trait bound `[u8]: LowerHex` is not satisfied`
    info!("card id = {:02x}", id);

I'm not sure if it's an explicit goal to make defmt log syntax a superset of std's formatting, but it would be very nice if it was, as it allows porting code super easily. As it stands now, it almost is :)

Dirbaio avatar Dec 21 '21 09:12 Dirbaio