macros: Consistently create Incoming* types from Incoming derive
… as a type alias if there are no lifetime generics on the input type.
This commit is contained in:
parent
5a791b3c6e
commit
54f9db8ccc
@ -1,4 +1,4 @@
|
|||||||
use ruma_common::api::{ruma_api, IncomingRequest};
|
use ruma_common::api::{ruma_api, IncomingRequest as _};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use ruma_common::{
|
use ruma_common::api::{
|
||||||
api::{
|
error::{FromHttpResponseError, IntoHttpError, MatrixError},
|
||||||
error::{FromHttpResponseError, IntoHttpError, MatrixError},
|
ruma_api, IncomingResponse, OutgoingResponse,
|
||||||
ruma_api, IncomingResponse, OutgoingResponse,
|
|
||||||
},
|
|
||||||
serde::Incoming,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
@ -25,7 +22,6 @@ ruma_api! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Incoming)]
|
|
||||||
pub struct Response;
|
pub struct Response;
|
||||||
|
|
||||||
impl IncomingResponse for Response {
|
impl IncomingResponse for Response {
|
||||||
|
@ -5,8 +5,8 @@ use syn::{
|
|||||||
parse_quote,
|
parse_quote,
|
||||||
punctuated::Punctuated,
|
punctuated::Punctuated,
|
||||||
AngleBracketedGenericArguments, Attribute, Data, DeriveInput, GenericArgument, GenericParam,
|
AngleBracketedGenericArguments, Attribute, Data, DeriveInput, GenericArgument, GenericParam,
|
||||||
Generics, Ident, ParenthesizedGenericArguments, Path, PathArguments, Token, Type, TypePath,
|
Generics, Ident, ItemType, ParenthesizedGenericArguments, Path, PathArguments, Token, Type,
|
||||||
TypeReference, TypeSlice,
|
TypePath, TypeReference, TypeSlice,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util::import_ruma_common;
|
use crate::util::import_ruma_common;
|
||||||
@ -38,8 +38,25 @@ pub fn expand_derive_incoming(mut ty_def: DeriveInput) -> syn::Result<TokenStrea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ident = format_ident!("Incoming{}", ty_def.ident, span = Span::call_site());
|
||||||
|
|
||||||
if !found_lifetime {
|
if !found_lifetime {
|
||||||
return Ok(TokenStream::new());
|
let doc = format!(
|
||||||
|
"Convenience type alias for [{}], for consistency with other [{}] types.",
|
||||||
|
&ty_def.ident, ident
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut type_alias: ItemType = parse_quote! { type X = Y; };
|
||||||
|
type_alias.vis = ty_def.vis.clone();
|
||||||
|
type_alias.ident = ident;
|
||||||
|
type_alias.generics = ty_def.generics.clone();
|
||||||
|
type_alias.ty =
|
||||||
|
Box::new(TypePath { qself: None, path: ty_def.ident.clone().into() }.into());
|
||||||
|
|
||||||
|
return Ok(quote! {
|
||||||
|
#[doc = #doc]
|
||||||
|
#type_alias
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut derives = vec![quote! { Debug }];
|
let mut derives = vec![quote! { Debug }];
|
||||||
@ -73,7 +90,7 @@ pub fn expand_derive_incoming(mut ty_def: DeriveInput) -> syn::Result<TokenStrea
|
|||||||
clean_generics(&mut ty_def.generics);
|
clean_generics(&mut ty_def.generics);
|
||||||
|
|
||||||
let doc = format!("'Incoming' variant of [{}].", &ty_def.ident);
|
let doc = format!("'Incoming' variant of [{}].", &ty_def.ident);
|
||||||
ty_def.ident = format_ident!("Incoming{}", ty_def.ident, span = Span::call_site());
|
ty_def.ident = ident;
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user