@@ -7,6 +7,63 @@ const HEX_WIDTH: usize = 2 + 2 * core::mem::size_of::<usize>();
7
7
#[ cfg( target_os = "fuchsia" ) ]
8
8
mod fuchsia;
9
9
10
+ /// A formatter for BacktraceFrames.
11
+ pub struct DebugBacktraceFrame < ' a > ( & ' a crate :: BacktraceFrame ) ;
12
+
13
+ impl < ' a > DebugBacktraceFrame < ' a > {
14
+ #[ allow( missing_docs) ]
15
+ pub fn new ( frame : & ' a crate :: BacktraceFrame ) -> Self {
16
+ Self ( frame)
17
+ }
18
+
19
+ /// Iterates over symbols in wrapped BacktraceFrame, and wraps them in DebugBacktraceSymbols.
20
+ pub fn symbols ( & self ) -> std:: vec:: Vec < DebugBacktraceSymbol < ' a > > {
21
+ self . 0 . symbols ( ) . iter ( ) . map ( DebugBacktraceSymbol :: new) . collect ( )
22
+ }
23
+
24
+ /// Same as symbols(), but filters out symbols that have no data
25
+ pub fn symbols_skip_empty ( & self ) -> std:: vec:: Vec < DebugBacktraceSymbol < ' a > > {
26
+ self . 0 . symbols ( ) . iter ( ) . filter ( |symbol| !symbol. is_empty ( ) ) . map ( DebugBacktraceSymbol :: new) . collect ( )
27
+ }
28
+ }
29
+
30
+ impl < ' a > fmt:: Debug for DebugBacktraceFrame < ' a > {
31
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
32
+ let mut d = f. debug_list ( ) ;
33
+ if !self . 0 . symbols ( ) . is_empty ( ) {
34
+ d. entries ( self . 0 . symbols ( ) . iter ( ) . map ( |symbol| DebugBacktraceSymbol :: new ( symbol) ) ) ;
35
+ }
36
+ d. finish ( )
37
+ }
38
+ }
39
+
40
+ /// A formatter for BacktraceSymbols.
41
+ pub struct DebugBacktraceSymbol < ' a > ( & ' a crate :: BacktraceSymbol ) ;
42
+
43
+ impl < ' a > DebugBacktraceSymbol < ' a > {
44
+ /// Create a new DebugBacktraceSymbol.
45
+ pub fn new ( frame : & ' a crate :: BacktraceSymbol ) -> Self {
46
+ Self ( frame)
47
+ }
48
+ }
49
+
50
+ impl < ' a > fmt:: Debug for DebugBacktraceSymbol < ' a > {
51
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
52
+ if self . 0 . name ( ) . is_none ( ) { return Ok ( ( ) ) ; }
53
+ let mut d = f. debug_map ( ) ;
54
+ let name = self . 0 . name ( ) ;
55
+ let file = self . 0
56
+ . filename ( )
57
+ . and_then ( |p| Some ( BytesOrWideString :: Bytes ( p. to_str ( ) ?. as_bytes ( ) ) ) ) ;
58
+ let line = self . 0 . lineno ( ) ;
59
+
60
+ if let Some ( ref name) = name { d. entry ( & "function" , name) ; }
61
+ if let Some ( ref file) = file { d. entry ( & "file" , file) ; }
62
+ if let Some ( ref line) = line { d. entry ( & "line" , line) ; }
63
+ d. finish ( )
64
+ }
65
+ }
66
+
10
67
/// A formatter for backtraces.
11
68
///
12
69
/// This type can be used to print a backtrace regardless of where the backtrace
0 commit comments