cosmwasm_vm/errors/
backtrace.rs1use core::fmt::{Debug, Display, Formatter, Result};
2use std::backtrace::Backtrace;
3
4pub struct BT(Box<Backtrace>);
6
7impl BT {
8 #[track_caller]
9 pub fn capture() -> Self {
10 BT(Box::new(Backtrace::capture()))
11 }
12}
13
14impl Debug for BT {
15 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
16 Debug::fmt(&self.0, f)
17 }
18}
19
20impl Display for BT {
21 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
22 Display::fmt(&self.0, f)
23 }
24}
25
26macro_rules! impl_from_err {
31 ($from:ty, $to:ty, $map:path) => {
32 impl From<$from> for $to {
33 fn from(err: $from) -> Self {
34 $map {
35 source: err,
36 backtrace: $crate::errors::backtrace::BT::capture(),
37 }
38 }
39 }
40 };
41}
42pub(crate) use impl_from_err;