use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Frame {
pub file: String,
pub line: u32,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Backtrace {
pub frames: Vec<Frame>,
}
impl Backtrace {
pub fn capture() -> Self {
let bt = backtrace::Backtrace::new();
let mut all_frames = Vec::new();
for frame in bt.frames() {
for symbol in frame.symbols() {
if let Some(filename) = symbol.filename() {
if let Some(line) = symbol.lineno() {
all_frames.push(Frame {
file: filename.to_string_lossy().to_string(),
line,
});
}
}
}
}
Backtrace { frames: all_frames }
}
}