From 54f9db8ccc5d18acb9df6e0006e9b5e4531f1a62 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 22 Mar 2022 10:27:56 +0100 Subject: [PATCH] macros: Consistently create Incoming* types from Incoming derive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … as a type alias if there are no lifetime generics on the input type. --- .../tests/api/path_arg_ordering.rs | 2 +- .../tests/api/ui/05-request-only.rs | 10 +++----- crates/ruma-macros/src/serde/incoming.rs | 25 ++++++++++++++++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/crates/ruma-common/tests/api/path_arg_ordering.rs b/crates/ruma-common/tests/api/path_arg_ordering.rs index e3d4cd2c..8cff98dc 100644 --- a/crates/ruma-common/tests/api/path_arg_ordering.rs +++ b/crates/ruma-common/tests/api/path_arg_ordering.rs @@ -1,4 +1,4 @@ -use ruma_common::api::{ruma_api, IncomingRequest}; +use ruma_common::api::{ruma_api, IncomingRequest as _}; ruma_api! { metadata: { diff --git a/crates/ruma-common/tests/api/ui/05-request-only.rs b/crates/ruma-common/tests/api/ui/05-request-only.rs index 12511b10..7cb3e49a 100644 --- a/crates/ruma-common/tests/api/ui/05-request-only.rs +++ b/crates/ruma-common/tests/api/ui/05-request-only.rs @@ -1,10 +1,7 @@ use bytes::BufMut; -use ruma_common::{ - api::{ - error::{FromHttpResponseError, IntoHttpError, MatrixError}, - ruma_api, IncomingResponse, OutgoingResponse, - }, - serde::Incoming, +use ruma_common::api::{ + error::{FromHttpResponseError, IntoHttpError, MatrixError}, + ruma_api, IncomingResponse, OutgoingResponse, }; ruma_api! { @@ -25,7 +22,6 @@ ruma_api! { } } -#[derive(Incoming)] pub struct Response; impl IncomingResponse for Response { diff --git a/crates/ruma-macros/src/serde/incoming.rs b/crates/ruma-macros/src/serde/incoming.rs index d621c771..096ef053 100644 --- a/crates/ruma-macros/src/serde/incoming.rs +++ b/crates/ruma-macros/src/serde/incoming.rs @@ -5,8 +5,8 @@ use syn::{ parse_quote, punctuated::Punctuated, AngleBracketedGenericArguments, Attribute, Data, DeriveInput, GenericArgument, GenericParam, - Generics, Ident, ParenthesizedGenericArguments, Path, PathArguments, Token, Type, TypePath, - TypeReference, TypeSlice, + Generics, Ident, ItemType, ParenthesizedGenericArguments, Path, PathArguments, Token, Type, + TypePath, TypeReference, TypeSlice, }; use crate::util::import_ruma_common; @@ -38,8 +38,25 @@ pub fn expand_derive_incoming(mut ty_def: DeriveInput) -> syn::Result syn::Result