1fad3a1d3Sopenharmony_ci#![allow(
2fad3a1d3Sopenharmony_ci    clippy::no_effect_underscore_binding,
3fad3a1d3Sopenharmony_ci    clippy::too_many_lines,
4fad3a1d3Sopenharmony_ci    clippy::used_underscore_binding
5fad3a1d3Sopenharmony_ci)]
6fad3a1d3Sopenharmony_ci
7fad3a1d3Sopenharmony_ci#[rustfmt::skip]
8fad3a1d3Sopenharmony_cimod gen;
9fad3a1d3Sopenharmony_ci
10fad3a1d3Sopenharmony_ciuse proc_macro2::{Ident, Literal, TokenStream};
11fad3a1d3Sopenharmony_ciuse ref_cast::RefCast;
12fad3a1d3Sopenharmony_ciuse std::fmt::{self, Debug};
13fad3a1d3Sopenharmony_ciuse std::ops::Deref;
14fad3a1d3Sopenharmony_ciuse syn::punctuated::Punctuated;
15fad3a1d3Sopenharmony_ci
16fad3a1d3Sopenharmony_ci#[derive(RefCast)]
17fad3a1d3Sopenharmony_ci#[repr(transparent)]
18fad3a1d3Sopenharmony_cipub struct Lite<T: ?Sized> {
19fad3a1d3Sopenharmony_ci    value: T,
20fad3a1d3Sopenharmony_ci}
21fad3a1d3Sopenharmony_ci
22fad3a1d3Sopenharmony_ci#[allow(non_snake_case)]
23fad3a1d3Sopenharmony_cipub fn Lite<T: ?Sized>(value: &T) -> &Lite<T> {
24fad3a1d3Sopenharmony_ci    Lite::ref_cast(value)
25fad3a1d3Sopenharmony_ci}
26fad3a1d3Sopenharmony_ci
27fad3a1d3Sopenharmony_ciimpl<T: ?Sized> Deref for Lite<T> {
28fad3a1d3Sopenharmony_ci    type Target = T;
29fad3a1d3Sopenharmony_ci
30fad3a1d3Sopenharmony_ci    fn deref(&self) -> &Self::Target {
31fad3a1d3Sopenharmony_ci        &self.value
32fad3a1d3Sopenharmony_ci    }
33fad3a1d3Sopenharmony_ci}
34fad3a1d3Sopenharmony_ci
35fad3a1d3Sopenharmony_ciimpl Debug for Lite<bool> {
36fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
37fad3a1d3Sopenharmony_ci        write!(formatter, "{}", self.value)
38fad3a1d3Sopenharmony_ci    }
39fad3a1d3Sopenharmony_ci}
40fad3a1d3Sopenharmony_ci
41fad3a1d3Sopenharmony_ciimpl Debug for Lite<u32> {
42fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
43fad3a1d3Sopenharmony_ci        write!(formatter, "{}", self.value)
44fad3a1d3Sopenharmony_ci    }
45fad3a1d3Sopenharmony_ci}
46fad3a1d3Sopenharmony_ci
47fad3a1d3Sopenharmony_ciimpl Debug for Lite<usize> {
48fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
49fad3a1d3Sopenharmony_ci        write!(formatter, "{}", self.value)
50fad3a1d3Sopenharmony_ci    }
51fad3a1d3Sopenharmony_ci}
52fad3a1d3Sopenharmony_ci
53fad3a1d3Sopenharmony_ciimpl Debug for Lite<String> {
54fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
55fad3a1d3Sopenharmony_ci        write!(formatter, "{:?}", self.value)
56fad3a1d3Sopenharmony_ci    }
57fad3a1d3Sopenharmony_ci}
58fad3a1d3Sopenharmony_ci
59fad3a1d3Sopenharmony_ciimpl Debug for Lite<Ident> {
60fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
61fad3a1d3Sopenharmony_ci        write!(formatter, "{:?}", self.value.to_string())
62fad3a1d3Sopenharmony_ci    }
63fad3a1d3Sopenharmony_ci}
64fad3a1d3Sopenharmony_ci
65fad3a1d3Sopenharmony_ciimpl Debug for Lite<Literal> {
66fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
67fad3a1d3Sopenharmony_ci        write!(formatter, "{}", self.value)
68fad3a1d3Sopenharmony_ci    }
69fad3a1d3Sopenharmony_ci}
70fad3a1d3Sopenharmony_ci
71fad3a1d3Sopenharmony_ciimpl Debug for Lite<TokenStream> {
72fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
73fad3a1d3Sopenharmony_ci        let string = self.value.to_string();
74fad3a1d3Sopenharmony_ci        if string.len() <= 80 {
75fad3a1d3Sopenharmony_ci            write!(formatter, "TokenStream(`{}`)", self.value)
76fad3a1d3Sopenharmony_ci        } else {
77fad3a1d3Sopenharmony_ci            formatter
78fad3a1d3Sopenharmony_ci                .debug_tuple("TokenStream")
79fad3a1d3Sopenharmony_ci                .field(&format_args!("`{}`", string))
80fad3a1d3Sopenharmony_ci                .finish()
81fad3a1d3Sopenharmony_ci        }
82fad3a1d3Sopenharmony_ci    }
83fad3a1d3Sopenharmony_ci}
84fad3a1d3Sopenharmony_ci
85fad3a1d3Sopenharmony_ciimpl<'a, T> Debug for Lite<&'a T>
86fad3a1d3Sopenharmony_ciwhere
87fad3a1d3Sopenharmony_ci    Lite<T>: Debug,
88fad3a1d3Sopenharmony_ci{
89fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
90fad3a1d3Sopenharmony_ci        Debug::fmt(Lite(self.value), formatter)
91fad3a1d3Sopenharmony_ci    }
92fad3a1d3Sopenharmony_ci}
93fad3a1d3Sopenharmony_ci
94fad3a1d3Sopenharmony_ciimpl<T> Debug for Lite<Box<T>>
95fad3a1d3Sopenharmony_ciwhere
96fad3a1d3Sopenharmony_ci    Lite<T>: Debug,
97fad3a1d3Sopenharmony_ci{
98fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
99fad3a1d3Sopenharmony_ci        Debug::fmt(Lite(&*self.value), formatter)
100fad3a1d3Sopenharmony_ci    }
101fad3a1d3Sopenharmony_ci}
102fad3a1d3Sopenharmony_ci
103fad3a1d3Sopenharmony_ciimpl<T> Debug for Lite<Vec<T>>
104fad3a1d3Sopenharmony_ciwhere
105fad3a1d3Sopenharmony_ci    Lite<T>: Debug,
106fad3a1d3Sopenharmony_ci{
107fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
108fad3a1d3Sopenharmony_ci        formatter
109fad3a1d3Sopenharmony_ci            .debug_list()
110fad3a1d3Sopenharmony_ci            .entries(self.value.iter().map(Lite))
111fad3a1d3Sopenharmony_ci            .finish()
112fad3a1d3Sopenharmony_ci    }
113fad3a1d3Sopenharmony_ci}
114fad3a1d3Sopenharmony_ci
115fad3a1d3Sopenharmony_ciimpl<T, P> Debug for Lite<Punctuated<T, P>>
116fad3a1d3Sopenharmony_ciwhere
117fad3a1d3Sopenharmony_ci    Lite<T>: Debug,
118fad3a1d3Sopenharmony_ci    Lite<P>: Debug,
119fad3a1d3Sopenharmony_ci{
120fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
121fad3a1d3Sopenharmony_ci        let mut list = formatter.debug_list();
122fad3a1d3Sopenharmony_ci        for pair in self.pairs() {
123fad3a1d3Sopenharmony_ci            let (node, punct) = pair.into_tuple();
124fad3a1d3Sopenharmony_ci            list.entry(Lite(node));
125fad3a1d3Sopenharmony_ci            list.entries(punct.map(Lite));
126fad3a1d3Sopenharmony_ci        }
127fad3a1d3Sopenharmony_ci        list.finish()
128fad3a1d3Sopenharmony_ci    }
129fad3a1d3Sopenharmony_ci}
130fad3a1d3Sopenharmony_ci
131fad3a1d3Sopenharmony_cistruct Present;
132fad3a1d3Sopenharmony_ci
133fad3a1d3Sopenharmony_ciimpl Debug for Present {
134fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
135fad3a1d3Sopenharmony_ci        formatter.write_str("Some")
136fad3a1d3Sopenharmony_ci    }
137fad3a1d3Sopenharmony_ci}
138fad3a1d3Sopenharmony_ci
139fad3a1d3Sopenharmony_cistruct Option {
140fad3a1d3Sopenharmony_ci    present: bool,
141fad3a1d3Sopenharmony_ci}
142fad3a1d3Sopenharmony_ci
143fad3a1d3Sopenharmony_ciimpl Debug for Option {
144fad3a1d3Sopenharmony_ci    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
145fad3a1d3Sopenharmony_ci        formatter.write_str(if self.present { "Some" } else { "None" })
146fad3a1d3Sopenharmony_ci    }
147fad3a1d3Sopenharmony_ci}
148