Skip to content

Commit

Permalink
Update code with rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
justahero committed Mar 26, 2021
1 parent c9588e6 commit b9f54f5
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions firmware/qemu/src/bin/hints_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use defmt_semihosting as _; // global logger
#[entry]
fn main() -> ! {
{
struct S1 { x: &'static str, y: u8 }
struct S1 {
x: &'static str,
y: u8,
}
impl defmt::Format for S1 {
fn format(&self, f: defmt::Formatter) {
write!(f, "S1 {{ x: {=str:?}, y: {=u8:?} }}", self.x, self.y)
Expand All @@ -24,7 +27,9 @@ fn main() -> ! {
}

{
struct S2 { x: u8 }
struct S2 {
x: u8,
}
impl defmt::Format for S2 {
fn format(&self, f: defmt::Formatter) {
write!(f, "S2 {{ x: {=u8:x} }}", self.x)
Expand All @@ -37,34 +42,73 @@ fn main() -> ! {

{
#[derive(defmt::Format)]
struct S { x: &'static str, y: u32 }
struct S {
x: &'static str,
y: u32,
}

// 0.1.x version
defmt::warn!("Debug hint: {:?}", S { x: "hello", y: 512 });
// 0.2.x version, results in same output
defmt::warn!(" no hint: {}", S { x: "hello", y: 1024 });
defmt::warn!(
" no hint: {}",
S {
x: "hello",
y: 1024
}
);
}

{
// nested struct
struct S1 { x: u16, y: u32 }
struct S1 {
x: u16,
y: u32,
}
impl defmt::Format for S1 {
fn format(&self, f: defmt::Formatter) {
write!(f, "S1 {{ x: {=u16:b}, y: {} }}", self.x, self.y);
}
}

struct S2 { s: S1, z: u8 }
struct S2 {
s: S1,
z: u8,
}
impl defmt::Format for S2 {
fn format(&self, f: defmt::Formatter) {
write!(f, "S2 {{ s: {:?}, z: {} }}", self.s, self.z);
}
}

defmt::info!("{}", S2 { s: S1 { x: 4, y: 12 }, z: 20 });
defmt::info!("{:?}", S2 { s: S1 { x: 4, y: 12 }, z: 20 });
defmt::info!("{:x}", S2 { s: S1 { x: 4, y: 12 }, z: 20 });
defmt::info!("{:b}", S2 { s: S1 { x: 4, y: 12 }, z: 20 });
defmt::info!(
"{}",
S2 {
s: S1 { x: 4, y: 12 },
z: 20
}
);
defmt::info!(
"{:?}",
S2 {
s: S1 { x: 4, y: 12 },
z: 20
}
);
defmt::info!(
"{:x}",
S2 {
s: S1 { x: 4, y: 12 },
z: 20
}
);
defmt::info!(
"{:b}",
S2 {
s: S1 { x: 4, y: 12 },
z: 20
}
);
}

loop {
Expand Down

0 comments on commit b9f54f5

Please sign in to comment.