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 9, 2025
1 parent 29a2307 commit 805f586
Showing 1 changed file with 25 additions and 0 deletions.
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 805f586

Please sign in to comment.