Add Frames iterator for Backtrace
This commit is contained in:
parent
a62a76047e
commit
050643a960
2 changed files with 92 additions and 38 deletions
|
@ -147,11 +147,14 @@ fn _assert_send_sync() {
|
|||
_assert::<Backtrace>();
|
||||
}
|
||||
|
||||
struct BacktraceFrame {
|
||||
/// A single frame of a backtrace.
|
||||
#[unstable(feature = "backtrace_frames", issue = "79676")]
|
||||
pub struct BacktraceFrame {
|
||||
frame: RawFrame,
|
||||
symbols: Vec<BacktraceSymbol>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum RawFrame {
|
||||
Actual(backtrace_rs::Frame),
|
||||
#[cfg(test)]
|
||||
|
@ -196,6 +199,14 @@ impl fmt::Debug for Backtrace {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for BacktraceFrame {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut dbg = fmt.debug_list();
|
||||
dbg.entries(&self.symbols);
|
||||
dbg.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for BacktraceSymbol {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// FIXME: improve formatting: https://github.com/rust-lang/rust/issues/65280
|
||||
|
@ -353,6 +364,14 @@ impl Backtrace {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Backtrace {
|
||||
/// Returns an iterator over the backtrace frames.
|
||||
#[unstable(feature = "backtrace_frames", issue = "79676")]
|
||||
pub fn frames(&'a self) -> &'a [BacktraceFrame] {
|
||||
if let Inner::Captured(c) = &self.inner { &c.force().frames } else { &[] }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Backtrace {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let capture = match &self.inner {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue