macros: Move ensure_feature_presence check from ruma_api to request / response
This commit is contained in:
		
							parent
							
								
									2451f33a64
								
							
						
					
					
						commit
						7d018897b0
					
				| @ -50,8 +50,6 @@ pub struct Api { | |||||||
| 
 | 
 | ||||||
| impl Api { | impl Api { | ||||||
|     pub fn expand_all(self) -> TokenStream { |     pub fn expand_all(self) -> TokenStream { | ||||||
|         let maybe_feature_error = ensure_feature_presence().map(syn::Error::to_compile_error); |  | ||||||
| 
 |  | ||||||
|         let ruma_common = import_ruma_common(); |         let ruma_common = import_ruma_common(); | ||||||
| 
 | 
 | ||||||
|         let metadata = &self.metadata; |         let metadata = &self.metadata; | ||||||
| @ -73,8 +71,6 @@ impl Api { | |||||||
|         let metadata_doc = format!("Metadata for the `{}` API endpoint.", name.value()); |         let metadata_doc = format!("Metadata for the `{}` API endpoint.", name.value()); | ||||||
| 
 | 
 | ||||||
|         quote! { |         quote! { | ||||||
|             #maybe_feature_error |  | ||||||
| 
 |  | ||||||
|             // For some reason inlining the expression causes issues with macro parsing
 |             // For some reason inlining the expression causes issues with macro parsing
 | ||||||
|             const _RUMA_API_VERSION_HISTORY: #ruma_common::api::VersionHistory = #history; |             const _RUMA_API_VERSION_HISTORY: #ruma_common::api::VersionHistory = #history; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ use syn::{ | |||||||
| 
 | 
 | ||||||
| use super::{ | use super::{ | ||||||
|     attribute::{DeriveRequestMeta, RequestMeta}, |     attribute::{DeriveRequestMeta, RequestMeta}, | ||||||
|  |     ensure_feature_presence, | ||||||
|     util::collect_lifetime_idents, |     util::collect_lifetime_idents, | ||||||
| }; | }; | ||||||
| use crate::util::import_ruma_common; | use crate::util::import_ruma_common; | ||||||
| @ -21,12 +22,16 @@ pub fn expand_request(attr: RequestAttr, item: ItemStruct) -> TokenStream { | |||||||
|     let ruma_common = import_ruma_common(); |     let ruma_common = import_ruma_common(); | ||||||
|     let ruma_macros = quote! { #ruma_common::exports::ruma_macros }; |     let ruma_macros = quote! { #ruma_common::exports::ruma_macros }; | ||||||
| 
 | 
 | ||||||
|  |     let maybe_feature_error = ensure_feature_presence().map(syn::Error::to_compile_error); | ||||||
|  | 
 | ||||||
|     let error_ty = attr.0.first().map_or_else( |     let error_ty = attr.0.first().map_or_else( | ||||||
|         || quote! { #ruma_common::api::error::MatrixError }, |         || quote! { #ruma_common::api::error::MatrixError }, | ||||||
|         |DeriveRequestMeta::Error(ty)| quote! { #ty }, |         |DeriveRequestMeta::Error(ty)| quote! { #ty }, | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|  |         #maybe_feature_error | ||||||
|  | 
 | ||||||
|         #[derive(
 |         #[derive(
 | ||||||
|             Clone, |             Clone, | ||||||
|             Debug, |             Debug, | ||||||
|  | |||||||
| @ -9,7 +9,10 @@ use syn::{ | |||||||
|     DeriveInput, Field, Generics, Ident, ItemStruct, Lifetime, Token, Type, |     DeriveInput, Field, Generics, Ident, ItemStruct, Lifetime, Token, Type, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use super::attribute::{DeriveResponseMeta, ResponseMeta}; | use super::{ | ||||||
|  |     attribute::{DeriveResponseMeta, ResponseMeta}, | ||||||
|  |     ensure_feature_presence, | ||||||
|  | }; | ||||||
| use crate::util::import_ruma_common; | use crate::util::import_ruma_common; | ||||||
| 
 | 
 | ||||||
| mod incoming; | mod incoming; | ||||||
| @ -19,6 +22,8 @@ pub fn expand_response(attr: ResponseAttr, item: ItemStruct) -> TokenStream { | |||||||
|     let ruma_common = import_ruma_common(); |     let ruma_common = import_ruma_common(); | ||||||
|     let ruma_macros = quote! { #ruma_common::exports::ruma_macros }; |     let ruma_macros = quote! { #ruma_common::exports::ruma_macros }; | ||||||
| 
 | 
 | ||||||
|  |     let maybe_feature_error = ensure_feature_presence().map(syn::Error::to_compile_error); | ||||||
|  | 
 | ||||||
|     let error_ty = attr |     let error_ty = attr | ||||||
|         .0 |         .0 | ||||||
|         .iter() |         .iter() | ||||||
| @ -29,6 +34,8 @@ pub fn expand_response(attr: ResponseAttr, item: ItemStruct) -> TokenStream { | |||||||
|         .unwrap_or_else(|| quote! { #ruma_common::api::error::MatrixError }); |         .unwrap_or_else(|| quote! { #ruma_common::api::error::MatrixError }); | ||||||
| 
 | 
 | ||||||
|     quote! { |     quote! { | ||||||
|  |         #maybe_feature_error | ||||||
|  | 
 | ||||||
|         #[derive(
 |         #[derive(
 | ||||||
|             Clone, |             Clone, | ||||||
|             Debug, |             Debug, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user