n0_snafu/
spantrace.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#[cfg(not(target_arch = "wasm32"))]
#[derive(Clone)]
pub struct SpanTrace(tracing_error::SpanTrace);

#[cfg(target_arch = "wasm32")]
#[derive(Clone)]
pub struct SpanTrace; // Empty struct for WASM

#[cfg(not(target_arch = "wasm32"))]
impl std::fmt::Debug for SpanTrace {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}

#[cfg(target_arch = "wasm32")]
impl std::fmt::Debug for SpanTrace {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "SpanTrace(wasm - not available)")
    }
}

#[cfg(not(target_arch = "wasm32"))]
impl std::fmt::Display for SpanTrace {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}

#[cfg(target_arch = "wasm32")]
impl std::fmt::Display for SpanTrace {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "SpanTrace not available on WASM")
    }
}

#[cfg(not(target_arch = "wasm32"))]
impl std::ops::Deref for SpanTrace {
    type Target = tracing_error::SpanTrace;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

#[cfg(not(target_arch = "wasm32"))]
impl snafu::GenerateImplicitData for SpanTrace {
    fn generate() -> Self {
        Self(tracing_error::SpanTrace::capture())
    }
}

#[cfg(target_arch = "wasm32")]
impl snafu::GenerateImplicitData for SpanTrace {
    fn generate() -> Self {
        Self // No-op for WASM
    }
}