Skip to content

Commit

Permalink
Add an impl Format for PanicInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
dflemstr committed Jun 28, 2024
1 parent 29f1472 commit 61a4fbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions defmt/src/impls/core_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod cell;
mod net;
mod num;
mod ops;
mod panic;
mod ptr;
mod slice;

Expand Down
26 changes: 26 additions & 0 deletions defmt/src/impls/core_/panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use core::panic;

use super::*;

impl<'a> Format for panic::PanicInfo<'a> {
fn format(&self, f: Formatter) {
crate::write!(f, "panicked at {}:", self.location());
// TODO: consider supporting self.message() once stabilized, or add a crate feature for
// conditional support
if let Some(msg) = self.payload().downcast_ref::<&'static str>() {
crate::write!(f, "\n{=str}", msg);
}
}
}

impl<'a> Format for panic::Location<'a> {
fn format(&self, f: Formatter) {
crate::write!(
f,
"{=str}:{=u32}:{=u32}",
self.file(),
self.line(),
self.column()
);
}
}

0 comments on commit 61a4fbb

Please sign in to comment.