color_backtrace

Struct BacktracePrinter

Source
pub struct BacktracePrinter { /* private fields */ }
Expand description

Pretty-printer for backtraces and PanicInfo structs.

Implementations§

Source§

impl BacktracePrinter

Builder functions.

Source

pub fn new() -> Self

Alias for BacktracePrinter::default.

Examples found in repository?
examples/custom_message.rs (line 4)
3
4
5
6
7
8
fn main() {
    BacktracePrinter::new()
        .message("Custom message!")
        .install(default_output_stream());
    assert_eq!(1, 2);
}
More examples
Hide additional examples
examples/force_color.rs (line 24)
21
22
23
24
25
26
27
fn main() {
    use color_backtrace::{termcolor::StandardStream, BacktracePrinter};
    let out = StandardStream::stderr(termcolor::ColorChoice::Always);
    BacktracePrinter::new().install(out);

    fn1();
}
Source

pub fn color_scheme(self, colors: ColorScheme) -> Self

Alter the color scheme.

Defaults to ColorScheme::classic().

Source

pub fn message(self, message: impl Into<String>) -> Self

Controls the “greeting” message of the panic.

Defaults to "The application panicked (crashed)".

Examples found in repository?
examples/custom_message.rs (line 5)
3
4
5
6
7
8
fn main() {
    BacktracePrinter::new()
        .message("Custom message!")
        .install(default_output_stream());
    assert_eq!(1, 2);
}
Source

pub fn verbosity(self, v: Verbosity) -> Self

Controls the verbosity level used when installed as panic handler.

Defaults to Verbosity::from_env().

Source

pub fn lib_verbosity(self, v: Verbosity) -> Self

Controls the lib verbosity level used when formatting user provided traces.

Defaults to Verbosity::lib_from_env().

Source

pub fn strip_function_hash(self, strip: bool) -> Self

Controls whether the hash part of functions is stripped.

Defaults to false.

Source

pub fn print_addresses(self, val: bool) -> Self

Controls whether addresses (or module offsets if available) should be printed.

Defaults to false.

Source

pub fn add_frame_filter(self, filter: Box<FilterCallback>) -> Self

Add a custom filter to the set of frame filters

Filters are run in the order they are added.

§Example
use color_backtrace::{default_output_stream, BacktracePrinter};

BacktracePrinter::new()
    .add_frame_filter(Box::new(|frames| {
        frames.retain(|x| matches!(&x.name, Some(n) if !n.starts_with("blabla")))
    }))
    .install(default_output_stream());
Source

pub fn clear_frame_filters(self) -> Self

Clears all filters associated with this printer, including the default filter

Source§

impl BacktracePrinter

Routines for putting the panic printer to use.

Source

pub fn install(self, out: impl WriteColor + Sync + Send + 'static)

Install the color_backtrace handler with default settings.

Output streams can be created via default_output_stream() or using any other stream that implements termcolor::WriteColor.

Examples found in repository?
examples/custom_message.rs (line 6)
3
4
5
6
7
8
fn main() {
    BacktracePrinter::new()
        .message("Custom message!")
        .install(default_output_stream());
    assert_eq!(1, 2);
}
More examples
Hide additional examples
examples/force_color.rs (line 24)
21
22
23
24
25
26
27
fn main() {
    use color_backtrace::{termcolor::StandardStream, BacktracePrinter};
    let out = StandardStream::stderr(termcolor::ColorChoice::Always);
    BacktracePrinter::new().install(out);

    fn1();
}
Source

pub fn into_panic_handler( self, out: impl WriteColor + Sync + Send + 'static, ) -> Box<dyn Fn(&PanicInfo<'_>) + Sync + Send + 'static>

Create a color_backtrace panic handler from this panic printer.

This can be used if you want to combine the handler with other handlers.

Source

pub fn print_trace( &self, trace: &Backtrace, out: &mut impl WriteColor, ) -> Result<(), Error>

Pretty-prints a backtrace::Backtrace to an output stream.

Source

pub fn format_trace_to_string(&self, trace: &Backtrace) -> Result<String, Error>

Pretty-print a backtrace to a String, using VT100 color codes.

Examples found in repository?
examples/fmt_to_string.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn main() -> Result<(), std::io::Error> {
    let trace = backtrace::Backtrace::new();
    let printer = BacktracePrinter::default();
    let str = printer.format_trace_to_string(&trace)?;

    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(())
}
Source

pub fn print_panic_info( &self, pi: &PanicInfo<'_>, out: &mut impl WriteColor, ) -> Result<(), Error>

Pretty-prints a PanicInfo struct to an output stream.

Trait Implementations§

Source§

impl Clone for BacktracePrinter

Source§

fn clone(&self) -> BacktracePrinter

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BacktracePrinter

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BacktracePrinter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.