Skip to content

add display hints e.g. :x, :b, :a#313

Merged
bors[bot] merged 35 commits intomainfrom
display-hints
Dec 18, 2020
Merged

add display hints e.g. :x, :b, :a#313
bors[bot] merged 35 commits intomainfrom
display-hints

Conversation

@japaric
Copy link
Copy Markdown
Member

@japaric japaric commented Dec 17, 2020

breaking-change this changes the format string syntax as specified in RFC #270

// OLD syntax: will be rejected
info!("{:u8}", 42);

// NEW syntax: types are prefixed by '='; display hints are prefixed by ':'
info!("{=u8:x}", 42);

// Note that this works too and is now in line with the Rust std formatting syntax
info!("{:x}", 42);

Display hints that have been implemented:

  • Binary (:b), e.g. 0b1010
  • Upper case hexadecimal (:X), e.g. 0xA0
  • Lower case hexadecimal (:x), e.g. 0xa0
  • ASCII (:a), e.g. b"he\xffllo (works on byte slices [u8])
  • Debug (:?), e.g. "Hello" (works on strings)

TODO

  • update book and API doc

FIXME

  • derive(Format) on structs that contains string fields formats those fields "Display"-style (w/o double quotes)

(may not be necessary to block this PR on that fix though)

Comment thread parser/src/lib.rs Outdated
Comment thread parser/src/lib.rs Outdated
Comment thread parser/src/lib.rs Outdated
Comment thread parser/src/lib.rs

#[test]
fn ty() {
fn all_types() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread parser/src/lib.rs Outdated
Comment thread tests/encode.rs
let g = Formatter { inner: f };

write!(g, "bitfields {0:0..7} {0:9..14}", 0b0110_0011_1101_0010u16);
write!(g, "bitfields {0=0..7} {0=9..14}", 0b0110_0011_1101_0010u16);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add qemu tests for bitfields + display hints combinations

Comment thread parser/src/lib.rs Outdated
this function parses a single format parameter
to use the new syntax
this function parses a complete format string
to use the new syntax
also fix parsing of array types ("=[u8; 3]")
"{}" and "{0}" are now valid format strings
to use the new syntax
to use the new syntax
to use the new syntax
to use the new syntax
and apply display hints to byte slices / arrays
this mode rejects unknown display hints
use strict mode when parsing strings used in the write! and logging macros
do not use the strict mode when decoding defmt data in e.g. probe-run
the signature of `parse` and `parse_param` changed
@Lotterleben Lotterleben mentioned this pull request Dec 18, 2020
@japaric
Copy link
Copy Markdown
Member Author

japaric commented Dec 18, 2020

bors r+

@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Dec 18, 2020

Build succeeded:

@bors bors Bot merged commit c4461eb into main Dec 18, 2020
@bors bors Bot deleted the display-hints branch December 18, 2020 15:24
Comment thread book/src/eval-order.md
``` rust
# extern crate defmt;
defmt::info!("x={:?}", foo());
defmt::info!("x={=?}", foo());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, ? is a display hint, so why does =? also work here?

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