Skip to content

Commit

Permalink
feat: add std example
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyNova016 authored and athre0z committed Feb 6, 2025
1 parent 85f3e64 commit a845ff9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ btparse = { git = "https://github.com/yaahc/btparse.git", rev = "54f9ddb8c7c8f8e
[[example]]
name = "fmt_to_string"
required-features = ["use-backtrace-crate"]

[[example]]
name = "fmt_to_string_std"
required-features = ["use-btparse-crate"]
25 changes: 25 additions & 0 deletions examples/fmt_to_string_std.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use color_backtrace::BacktracePrinter;

fn main() -> Result<(), std::io::Error> {
// Start your trace
let trace = std::backtrace::Backtrace::force_capture();

// Do stuff...

// And print!
let bt = color_backtrace::btparse::deserialize(&trace).unwrap();
let printer = BacktracePrinter::default();
let str = printer.format_trace_to_string(&bt)?;

if cfg!(windows) {
println!(
"Warning: on Windows, you'll have to enable VT100 \
printing for your app in order for this to work \
correctly. This example doesn't do this."
);
}

println!("{}", str);

Ok(())
}

0 comments on commit a845ff9

Please sign in to comment.