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! {
|
||||
/// Data in the request body.
|
||||
#[derive(
|
||||
Debug,
|
||||
#ruma_macros::_FakeDeriveRumaApi,
|
||||
#serde::Serialize,
|
||||
#derive_deserialize
|
||||
#[derive(Debug, #ruma_macros::_FakeDeriveRumaApi)]
|
||||
#[cfg_attr(feature = "client", derive(#serde::Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "server",
|
||||
derive(#ruma_common::serde::Incoming, #derive_deserialize)
|
||||
)]
|
||||
#[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))]
|
||||
#serde_attr
|
||||
struct RequestBody< #(#lifetimes),* > { #(#fields),* }
|
||||
}
|
||||
@ -242,13 +241,12 @@ impl Request {
|
||||
|
||||
quote! {
|
||||
/// Data in the request's query string.
|
||||
#[derive(
|
||||
Debug,
|
||||
#ruma_macros::_FakeDeriveRumaApi,
|
||||
#serde::Serialize,
|
||||
#derive_deserialize
|
||||
#[derive(Debug, #ruma_macros::_FakeDeriveRumaApi)]
|
||||
#[cfg_attr(feature = "client", derive(#serde::Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "server",
|
||||
derive(#ruma_common::serde::Incoming, #derive_deserialize)
|
||||
)]
|
||||
#[cfg_attr(feature = "server", derive(#ruma_common::serde::Incoming))]
|
||||
struct RequestQuery< #(#lifetimes),* > #def
|
||||
}
|
||||
});
|
||||
|
@ -99,7 +99,10 @@ impl Response {
|
||||
|
||||
let response_body_struct = (!self.has_raw_body()).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)] });
|
||||
@ -107,12 +110,8 @@ impl Response {
|
||||
|
||||
quote! {
|
||||
/// Data in the response body.
|
||||
#[derive(
|
||||
Debug,
|
||||
#ruma_macros::_FakeDeriveRumaApi,
|
||||
#ruma_common::serde::Incoming,
|
||||
#[derive(Debug, #ruma_macros::_FakeDeriveRumaApi)]
|
||||
#serde_derives
|
||||
)]
|
||||
#serde_attr
|
||||
struct ResponseBody { #(#fields),* }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user