Skip to content

Commit b3bc0d8

Browse files
RustyNova016athre0z
authored andcommitted
feat: add std example
1 parent a0bd198 commit b3bc0d8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

examples/fmt_to_string_std.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use color_backtrace::BacktracePrinter;
2+
3+
fn main() -> Result<(), std::io::Error> {
4+
// Start your trace
5+
let trace = std::backtrace::Backtrace::force_capture();
6+
7+
// Do stuff...
8+
9+
// And print!
10+
let bt = color_backtrace::btparse::deserialize(&trace).unwrap();
11+
let printer = BacktracePrinter::default();
12+
let str = printer.format_trace_to_string(&bt)?;
13+
14+
if cfg!(windows) {
15+
println!(
16+
"Warning: on Windows, you'll have to enable VT100 \
17+
printing for your app in order for this to work \
18+
correctly. This example doesn't do this."
19+
);
20+
}
21+
22+
println!("{}", str);
23+
24+
Ok(())
25+
}

0 commit comments

Comments
 (0)