Skip to content

Commit eae54c0

Browse files
committed
Add example of no_std BT
1 parent 417123a commit eae54c0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/std/src/errors/backtrace.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct BT(Box<dyn Printable>);
88
impl BT {
99
#[track_caller]
1010
pub fn capture() -> Self {
11+
// in case of no_std, we can fill with a stub here
1112
#[cfg(target_arch = "wasm32")]
1213
return BT(Box::new(std::backtrace::Backtrace::disabled()));
1314
#[cfg(not(target_arch = "wasm32"))]
@@ -47,3 +48,22 @@ macro_rules! impl_from_err {
4748
};
4849
}
4950
pub(crate) use impl_from_err;
51+
52+
#[cfg(test)]
53+
mod tests {
54+
use super::*;
55+
56+
#[test]
57+
fn bt_works_without_std() {
58+
#[derive(Debug)]
59+
struct BacktraceStub;
60+
61+
impl Display for BacktraceStub {
62+
fn fmt(&self, _f: &mut Formatter<'_>) -> Result {
63+
Ok(())
64+
}
65+
}
66+
67+
_ = BT(Box::new(BacktraceStub));
68+
}
69+
}

0 commit comments

Comments
 (0)