macros: Reduce codegen by feature-gating Serialize and Deserialize derives
… this makes it faster to compiler ruma-*-api with either the client or server feature inactive.
This commit is contained in:
parent
7fbb28f223
commit
7a5be040fd
@ -214,13 +214,12 @@ impl Request {
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// Data in the request body.
|
/// Data in the request body.
|
||||||
#[derive(
|
#[derive(Debug, #ruma_macros::_FakeDeriveRumaApi)]
|
||||||
Debug,
|
#[cfg_attr(feature = "client", derive(#serde::Serialize))]
|
||||||
#ruma_macros::_FakeDeriveRumaApi,
|
#[cfg_attr(
|
||||||
#serde::Serialize,
|
feature = "server",
|
||||||
#derive_deserialize
|
derive(#ruma_common::serde::Incoming, #derive_deserialize)
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))]
|
|
||||||
#serde_attr
|
#serde_attr
|
||||||
struct RequestBody< #(#lifetimes),* > { #(#fields),* }
|
struct RequestBody< #(#lifetimes),* > { #(#fields),* }
|
||||||
}
|
}
|
||||||
@ -242,13 +241,12 @@ impl Request {
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// Data in the request's query string.
|
/// Data in the request's query string.
|
||||||
#[derive(
|
#[derive(Debug, #ruma_macros::_FakeDeriveRumaApi)]
|
||||||
Debug,
|
#[cfg_attr(feature = "client", derive(#serde::Serialize))]
|
||||||
#ruma_macros::_FakeDeriveRumaApi,
|
#[cfg_attr(
|
||||||
#serde::Serialize,
|
feature = "server",
|
||||||
#derive_deserialize
|
derive(#ruma_common::serde::Incoming, #derive_deserialize)
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))]
|
|
||||||
struct RequestQuery< #(#lifetimes),* > #def
|
struct RequestQuery< #(#lifetimes),* > #def
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -99,7 +99,10 @@ impl Response {
|
|||||||
|
|
||||||
let response_body_struct = (!self.has_raw_body()).then(|| {
|
let response_body_struct = (!self.has_raw_body()).then(|| {
|
||||||
let serde_derives = self.manual_body_serde.not().then(|| {
|
let serde_derives = self.manual_body_serde.not().then(|| {
|
||||||
quote! { #serde::Deserialize, #serde::Serialize }
|
quote! {
|
||||||
|
#[cfg_attr(feature = "client", derive(#serde::Deserialize))]
|
||||||
|
#[cfg_attr(feature = "server", derive(#serde::Serialize))]
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] });
|
let serde_attr = self.has_newtype_body().then(|| quote! { #[serde(transparent)] });
|
||||||
@ -107,12 +110,8 @@ impl Response {
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// Data in the response body.
|
/// Data in the response body.
|
||||||
#[derive(
|
#[derive(Debug, #ruma_macros::_FakeDeriveRumaApi)]
|
||||||
Debug,
|
|
||||||
#ruma_macros::_FakeDeriveRumaApi,
|
|
||||||
#ruma_common::serde::Incoming,
|
|
||||||
#serde_derives
|
#serde_derives
|
||||||
)]
|
|
||||||
#serde_attr
|
#serde_attr
|
||||||
struct ResponseBody { #(#fields),* }
|
struct ResponseBody { #(#fields),* }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user