Skip to main content

typed_quote/
alloc_imp.rs

1use alloc::{boxed::Box, rc::Rc};
2
3use crate::{IntoTokenTree, IntoTokens, ToTokenTree, ToTokens, sealed};
4
5impl<T: ?Sized + IntoTokens> sealed::IntoTokens for Box<T> {}
6impl<T: ?Sized + IntoTokens> IntoTokens for Box<T> {
7    #[cfg(feature = "proc-macro")]
8    fn into_tokens(self, tokens: &mut proc_macro::TokenStream) {
9        T::box_into_tokens(self, tokens)
10    }
11
12    #[cfg(feature = "proc-macro")]
13    fn into_token_stream(self) -> proc_macro::TokenStream {
14        T::box_into_token_stream(self)
15    }
16
17    #[cfg(feature = "proc-macro2")]
18    fn into_tokens2(self, tokens: &mut proc_macro2::TokenStream) {
19        T::box_into_tokens2(self, tokens)
20    }
21
22    #[cfg(feature = "proc-macro2")]
23    fn into_token_stream2(self) -> proc_macro2::TokenStream {
24        T::box_into_token_stream2(self)
25    }
26
27    crate::impl_box_into_tokens! {}
28}
29
30impl<T: ?Sized + ToTokens> sealed::ToTokens for Box<T> {}
31impl<T: ?Sized + ToTokens> ToTokens for Box<T> {
32    #[cfg(feature = "proc-macro")]
33    fn to_tokens(&self, tokens: &mut ::proc_macro::TokenStream) {
34        T::to_tokens(self, tokens)
35    }
36    #[cfg(feature = "proc-macro")]
37    fn to_token_stream(&self) -> ::proc_macro::TokenStream {
38        T::to_token_stream(self)
39    }
40
41    #[cfg(feature = "proc-macro2")]
42    fn to_tokens2(&self, tokens: &mut ::proc_macro2::TokenStream) {
43        T::to_tokens2(self, tokens)
44    }
45    #[cfg(feature = "proc-macro2")]
46    fn to_token_stream2(&self) -> ::proc_macro2::TokenStream {
47        T::to_token_stream2(self)
48    }
49}
50
51impl<T: ?Sized + IntoTokenTree> sealed::IntoTokenTree for Box<T> {}
52impl<T: ?Sized + IntoTokenTree> IntoTokenTree for Box<T> {
53    #[cfg(feature = "proc-macro")]
54    fn into_token_tree(self) -> proc_macro::TokenTree {
55        T::box_into_token_tree(self)
56    }
57    #[cfg(feature = "proc-macro2")]
58    fn into_token_tree2(self) -> proc_macro2::TokenTree {
59        T::box_into_token_tree2(self)
60    }
61
62    crate::impl_box_into_token_tree! {}
63}
64
65impl<T: ?Sized + ToTokenTree> sealed::ToTokenTree for Box<T> {}
66impl<T: ?Sized + ToTokenTree> ToTokenTree for Box<T> {
67    #[cfg(feature = "proc-macro")]
68    fn to_token_tree(&self) -> proc_macro::TokenTree {
69        T::to_token_tree(self)
70    }
71    #[cfg(feature = "proc-macro2")]
72    fn to_token_tree2(&self) -> proc_macro2::TokenTree {
73        T::to_token_tree2(self)
74    }
75}
76
77impl<T: ?Sized + ToTokens> sealed::IntoTokens for Rc<T> {}
78impl<T: ?Sized + ToTokens> IntoTokens for Rc<T> {
79    #[cfg(feature = "proc-macro")]
80    fn into_tokens(self, tokens: &mut proc_macro::TokenStream) {
81        T::to_tokens(&self, tokens)
82    }
83
84    #[cfg(feature = "proc-macro")]
85    fn into_token_stream(self) -> proc_macro::TokenStream {
86        T::to_token_stream(&self)
87    }
88
89    #[cfg(feature = "proc-macro2")]
90    fn into_tokens2(self, tokens: &mut proc_macro2::TokenStream) {
91        T::to_tokens2(&self, tokens)
92    }
93
94    #[cfg(feature = "proc-macro2")]
95    fn into_token_stream2(self) -> proc_macro2::TokenStream {
96        T::to_token_stream2(&self)
97    }
98
99    #[cfg(feature = "proc-macro")]
100    fn box_into_tokens(self: Box<Self>, tokens: &mut ::proc_macro::TokenStream) {
101        T::to_tokens(&self, tokens)
102    }
103
104    #[cfg(feature = "proc-macro")]
105    fn box_into_token_stream(self: Box<Self>) -> ::proc_macro::TokenStream {
106        T::to_token_stream(&self)
107    }
108
109    #[cfg(feature = "proc-macro2")]
110    fn box_into_tokens2(self: Box<Self>, tokens: &mut ::proc_macro2::TokenStream) {
111        T::to_tokens2(&self, tokens)
112    }
113
114    #[cfg(feature = "proc-macro2")]
115    fn box_into_token_stream2(self: Box<Self>) -> ::proc_macro2::TokenStream {
116        T::to_token_stream2(&self)
117    }
118}
119
120impl<T: ?Sized + ToTokens> sealed::ToTokens for Rc<T> {}
121impl<T: ?Sized + ToTokens> ToTokens for Rc<T> {
122    #[cfg(feature = "proc-macro")]
123    fn to_tokens(&self, tokens: &mut ::proc_macro::TokenStream) {
124        T::to_tokens(self, tokens)
125    }
126    #[cfg(feature = "proc-macro")]
127    fn to_token_stream(&self) -> ::proc_macro::TokenStream {
128        T::to_token_stream(self)
129    }
130
131    #[cfg(feature = "proc-macro2")]
132    fn to_tokens2(&self, tokens: &mut ::proc_macro2::TokenStream) {
133        T::to_tokens2(self, tokens)
134    }
135    #[cfg(feature = "proc-macro2")]
136    fn to_token_stream2(&self) -> ::proc_macro2::TokenStream {
137        T::to_token_stream2(self)
138    }
139}
140
141impl<T: ?Sized + ToTokenTree> sealed::IntoTokenTree for Rc<T> {}
142impl<T: ?Sized + ToTokenTree> IntoTokenTree for Rc<T> {
143    #[cfg(feature = "proc-macro")]
144    fn into_token_tree(self) -> proc_macro::TokenTree {
145        T::to_token_tree(&self)
146    }
147    #[cfg(feature = "proc-macro2")]
148    fn into_token_tree2(self) -> proc_macro2::TokenTree {
149        T::to_token_tree2(&self)
150    }
151
152    #[cfg(feature = "alloc")]
153    #[cfg(feature = "proc-macro")]
154    fn box_into_token_tree(self: ::alloc::boxed::Box<Self>) -> proc_macro::TokenTree {
155        T::to_token_tree(&self)
156    }
157    #[cfg(feature = "alloc")]
158    #[cfg(feature = "proc-macro2")]
159    fn box_into_token_tree2(self: ::alloc::boxed::Box<Self>) -> proc_macro2::TokenTree {
160        T::to_token_tree2(&self)
161    }
162}
163
164impl<T: ?Sized + ToTokenTree> sealed::ToTokenTree for Rc<T> {}
165impl<T: ?Sized + ToTokenTree> ToTokenTree for Rc<T> {
166    #[cfg(feature = "proc-macro")]
167    fn to_token_tree(&self) -> proc_macro::TokenTree {
168        T::to_token_tree(self)
169    }
170    #[cfg(feature = "proc-macro2")]
171    fn to_token_tree2(&self) -> proc_macro2::TokenTree {
172        T::to_token_tree2(self)
173    }
174}