• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(
2     clippy::no_effect_underscore_binding,
3     clippy::too_many_lines,
4     clippy::used_underscore_binding
5 )]
6 
7 #[rustfmt::skip]
8 mod gen;
9 
10 use proc_macro2::{Ident, Literal, TokenStream};
11 use ref_cast::RefCast;
12 use std::fmt::{self, Debug};
13 use std::ops::Deref;
14 use syn::punctuated::Punctuated;
15 
16 #[derive(RefCast)]
17 #[repr(transparent)]
18 pub struct Lite<T: ?Sized> {
19     value: T,
20 }
21 
22 #[allow(non_snake_case)]
Lite<T: ?Sized>(value: &T) -> &Lite<T>23 pub fn Lite<T: ?Sized>(value: &T) -> &Lite<T> {
24     Lite::ref_cast(value)
25 }
26 
27 impl<T: ?Sized> Deref for Lite<T> {
28     type Target = T;
29 
deref(&self) -> &Self::Target30     fn deref(&self) -> &Self::Target {
31         &self.value
32     }
33 }
34 
35 impl Debug for Lite<bool> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result36     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
37         write!(formatter, "{}", self.value)
38     }
39 }
40 
41 impl Debug for Lite<u32> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result42     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
43         write!(formatter, "{}", self.value)
44     }
45 }
46 
47 impl Debug for Lite<usize> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result48     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
49         write!(formatter, "{}", self.value)
50     }
51 }
52 
53 impl Debug for Lite<String> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result54     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
55         write!(formatter, "{:?}", self.value)
56     }
57 }
58 
59 impl Debug for Lite<Ident> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result60     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
61         write!(formatter, "{:?}", self.value.to_string())
62     }
63 }
64 
65 impl Debug for Lite<Literal> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result66     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
67         write!(formatter, "{}", self.value)
68     }
69 }
70 
71 impl Debug for Lite<TokenStream> {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result72     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
73         let string = self.value.to_string();
74         if string.len() <= 80 {
75             write!(formatter, "TokenStream(`{}`)", self.value)
76         } else {
77             formatter
78                 .debug_tuple("TokenStream")
79                 .field(&format_args!("`{}`", string))
80                 .finish()
81         }
82     }
83 }
84 
85 impl<'a, T> Debug for Lite<&'a T>
86 where
87     Lite<T>: Debug,
88 {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result89     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
90         Debug::fmt(Lite(self.value), formatter)
91     }
92 }
93 
94 impl<T> Debug for Lite<Box<T>>
95 where
96     Lite<T>: Debug,
97 {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result98     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
99         Debug::fmt(Lite(&*self.value), formatter)
100     }
101 }
102 
103 impl<T> Debug for Lite<Vec<T>>
104 where
105     Lite<T>: Debug,
106 {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result107     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
108         formatter
109             .debug_list()
110             .entries(self.value.iter().map(Lite))
111             .finish()
112     }
113 }
114 
115 impl<T, P> Debug for Lite<Punctuated<T, P>>
116 where
117     Lite<T>: Debug,
118 {
fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result119     fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
120         formatter
121             .debug_list()
122             .entries(self.value.iter().map(Lite))
123             .finish()
124     }
125 }
126