1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use proc_macro2::TokenStream;
use quote::quote;
use syn::{punctuated::Punctuated, spanned::Spanned, Attribute, Field, Ident, Token};
use super::{api_metadata::Metadata, kw};
pub(crate) struct Response {
pub(super) response_kw: kw::response,
pub attributes: Vec<Attribute>,
pub fields: Punctuated<Field, Token![,]>,
}
impl Response {
pub(super) fn expand(
&self,
metadata: &Metadata,
error_ty: &TokenStream,
ruma_common: &TokenStream,
) -> TokenStream {
let ruma_macros = quote! { #ruma_common::exports::ruma_macros };
let docs =
format!("Data in the response from the `{}` API endpoint.", metadata.name.value());
let struct_attributes = &self.attributes;
let response_ident = Ident::new("Response", self.response_kw.span());
let fields = &self.fields;
quote! {
#[doc = #docs]
#[derive(
Clone,
Debug,
#ruma_macros::Response,
#ruma_common::serde::Incoming,
#ruma_common::serde::_FakeDeriveSerde,
)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[incoming_derive(!Deserialize, #ruma_macros::_FakeDeriveRumaApi)]
#[ruma_api(error_ty = #error_ty)]
#( #struct_attributes )*
pub struct #response_ident {
#fields
}
}
}
}