11use super :: * ;
22
33pub ( crate ) struct Template {
4+ pub ( crate ) axum : Option < bool > ,
45 pub ( crate ) escape : bool ,
56 pub ( crate ) generics : Generics ,
67 pub ( crate ) ident : Ident ,
@@ -12,7 +13,7 @@ impl Template {
1213 pub ( crate ) fn impls ( self ) -> TokenStream {
1314 let display_impl = self . display_impl ( ) ;
1415
15- let axum_into_response_impl = if cfg ! ( feature = "axum" ) {
16+ let axum_into_response_impl = if self . axum . unwrap_or ( cfg ! ( feature = "axum" ) ) {
1617 Some ( self . axum_into_response_impl ( ) )
1718 } else {
1819 None
@@ -113,6 +114,8 @@ impl Template {
113114 quote ! {
114115 impl #impl_generics :: axum:: response:: IntoResponse for #ident #ty_generics #where_clause {
115116 fn into_response( self ) -> :: axum:: response:: Response {
117+ extern crate alloc;
118+ use alloc:: string:: ToString ;
116119 (
117120 [ ( :: axum:: http:: header:: CONTENT_TYPE , #content_type) ] ,
118121 self . to_string( ) ,
@@ -161,11 +164,12 @@ mod tests {
161164
162165 assert_eq ! (
163166 Template {
164- ident: Ident :: new( "Foo" , Span :: call_site( ) ) ,
165- source: Source :: Literal ( LitStr :: new( "" , Span :: call_site( ) ) ) ,
166- mime: mime:: TEXT_PLAIN ,
167+ axum: None ,
167168 escape: false ,
168169 generics: Generics :: default ( ) ,
170+ ident: Ident :: new( "Foo" , Span :: call_site( ) ) ,
171+ mime: mime:: TEXT_PLAIN ,
172+ source: Source :: Literal ( LitStr :: new( "" , Span :: call_site( ) ) ) ,
169173 }
170174 . display_impl( )
171175 . to_string( ) ,
@@ -327,17 +331,21 @@ mod tests {
327331 fn axum_into_response_impl ( ) {
328332 assert_eq ! (
329333 Template {
330- ident: Ident :: new( "Foo" , Span :: call_site( ) ) ,
331- source: Source :: Literal ( LitStr :: new( "" , Span :: call_site( ) ) ) ,
332- mime: mime:: TEXT_PLAIN ,
334+ axum: Some ( true ) ,
333335 escape: false ,
334336 generics: Generics :: default ( ) ,
337+ ident: Ident :: new( "Foo" , Span :: call_site( ) ) ,
338+ mime: mime:: TEXT_PLAIN ,
339+ source: Source :: Literal ( LitStr :: new( "" , Span :: call_site( ) ) ) ,
335340 }
336341 . axum_into_response_impl( )
337342 . to_string( ) ,
338343 quote!(
339344 impl :: axum:: response:: IntoResponse for Foo {
340345 fn into_response( self ) -> :: axum:: response:: Response {
346+ extern crate alloc;
347+ use alloc:: string:: ToString ;
348+
341349 (
342350 [ ( :: axum:: http:: header:: CONTENT_TYPE , "text/plain" ) ] ,
343351 self . to_string( ) ,
0 commit comments