Crates.io | color-backtrace |
lib.rs | color-backtrace |
version | 0.6.1 |
source | src |
created_at | 2019-04-18 22:10:05.857791 |
updated_at | 2023-10-22 23:57:23.462988 |
description | Colorful panic backtraces |
homepage | |
repository | https://github.com/athre0z/color-backtrace |
max_upload_size | |
id | 128738 |
size | 57,867 |
A Rust library that makes panics a little less painful by nicely colorizing them and printing the relevant source snippets.
[dependencies]
color-backtrace = { version = "0.6" }
To enable it, simply place this code somewhere in your app initialization code:
color_backtrace::install();
If you want to customize some settings, you can instead do:
use color_backtrace::{default_output_stream, BacktracePrinter};
BacktracePrinter::new().message("Custom message!").install(default_output_stream());
Unfortunately, defining custom init functions run before tests are started is currently not supported in Rust. Since initializing color-backtrace in each and every test is tedious even when wrapping it into a function, I recommended using the ctor crate for this.
Somewhere, preferably in your crate's main module, put the following code:
#[cfg(test)]
mod tests {
use ctor::ctor;
#[ctor]
fn init_color_backtrace() {
color_backtrace::install();
}
}
You can also do this outside of a #[cfg(test)]
section, in which case the
panic handler is installed for both test and regular runs.