alumet 0.8.0

Modular framework for hardware and software measurement (including energy consumption and more).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::{any::Any, fmt::Debug};

/// A wrapper to pretty-print the panic payload returned by [`std::panic::catch_unwind`].
pub struct PrettyAny(pub Box<dyn Any + Send>);

impl Debug for PrettyAny {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        // Handle the common case of string messages: panic!("message here")
        // It also works with standard assertions: assert_eq!(a, b) produces a panic with a string
        if let Some(str) = self.0.downcast_ref::<&str>() {
            return f.write_str(str);
        }
        if let Some(str) = self.0.downcast_ref::<String>() {
            return f.write_str(str);
        }
        return self.0.fmt(f);
    }
}