dbg_pls/impls/
proc_macro2.rs

1use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
2
3use crate::{DebugPls, Formatter};
4
5impl DebugPls for TokenStream {
6    fn fmt(&self, f: Formatter<'_>) {
7        f.debug_list().entries(self.clone()).finish();
8    }
9}
10
11impl DebugPls for TokenTree {
12    fn fmt(&self, f: Formatter<'_>) {
13        match self {
14            TokenTree::Group(v0) => f.debug_tuple_struct("Group").field(v0),
15            TokenTree::Ident(v0) => f.debug_tuple_struct("Ident").field(v0),
16            TokenTree::Punct(v0) => f.debug_tuple_struct("Punct").field(v0),
17            TokenTree::Literal(v0) => f.debug_tuple_struct("Literal").field(v0),
18        }
19        .finish();
20    }
21}
22
23impl DebugPls for Span {
24    fn fmt(&self, f: Formatter<'_>) {
25        f.debug_ident("Span");
26    }
27}
28
29impl DebugPls for Ident {
30    fn fmt(&self, f: Formatter<'_>) {
31        f.write_expr(syn::ExprPath {
32            path: self.clone().into(),
33            attrs: vec![],
34            qself: None,
35        });
36    }
37}
38
39impl DebugPls for Group {
40    fn fmt(&self, f: Formatter<'_>) {
41        f.debug_struct("Group")
42            .field("delimiter", &self.delimiter())
43            .field("stream", &self.stream())
44            .finish();
45    }
46}
47
48impl DebugPls for Punct {
49    fn fmt(&self, f: Formatter<'_>) {
50        f.debug_struct("Punct")
51            .field("ch", &self.as_char())
52            .field("spacing", &self.spacing())
53            .finish();
54    }
55}
56
57impl DebugPls for Literal {
58    fn fmt(&self, f: Formatter<'_>) {
59        f.debug_struct("Literal").finish_non_exhaustive();
60    }
61}
62
63impl DebugPls for Spacing {
64    fn fmt(&self, f: Formatter<'_>) {
65        match self {
66            Spacing::Alone => f.debug_ident("Alone"),
67            Spacing::Joint => f.debug_ident("Joint"),
68        }
69    }
70}
71
72impl DebugPls for Delimiter {
73    fn fmt(&self, f: Formatter<'_>) {
74        match self {
75            Delimiter::Parenthesis => f.debug_ident("Parenthesis"),
76            Delimiter::Brace => f.debug_ident("Brace"),
77            Delimiter::Bracket => f.debug_ident("Bracket"),
78            Delimiter::None => f.debug_ident("None"),
79        }
80    }
81}