macros: Slightly simplify generated API trait impls
This commit is contained in:
parent
e3a8b6b81f
commit
4e7eeb8aa4
@ -70,7 +70,7 @@ pub mod v3 {
|
||||
#[cfg(feature = "client")]
|
||||
impl<'a> ruma_common::api::OutgoingRequest for Request<'a> {
|
||||
type EndpointError = crate::Error;
|
||||
type IncomingResponse = <Response as ruma_common::serde::Outgoing>::Incoming;
|
||||
type IncomingResponse = Response;
|
||||
|
||||
const METADATA: ruma_common::api::Metadata = METADATA;
|
||||
|
||||
|
@ -64,11 +64,16 @@ impl Request {
|
||||
quote! { request_query },
|
||||
);
|
||||
|
||||
let request_query_ty = if self.lifetimes.query.is_empty() {
|
||||
quote! { RequestQuery }
|
||||
} else {
|
||||
quote! { IncomingRequestQuery }
|
||||
};
|
||||
|
||||
let parse = quote! {
|
||||
let request_query: <RequestQuery as #ruma_common::serde::Outgoing>::Incoming =
|
||||
#ruma_common::serde::urlencoded::from_str(
|
||||
&request.uri().query().unwrap_or("")
|
||||
)?;
|
||||
let request_query: #request_query_ty = #ruma_common::serde::urlencoded::from_str(
|
||||
&request.uri().query().unwrap_or("")
|
||||
)?;
|
||||
|
||||
#decls
|
||||
};
|
||||
@ -144,17 +149,14 @@ impl Request {
|
||||
};
|
||||
|
||||
let extract_body = self.has_body_fields().then(|| {
|
||||
let body_lifetimes = (!self.lifetimes.body.is_empty()).then(|| {
|
||||
// duplicate the anonymous lifetime as many times as needed
|
||||
let lifetimes = std::iter::repeat(quote! { '_ }).take(self.lifetimes.body.len());
|
||||
quote! { < #( #lifetimes, )* > }
|
||||
});
|
||||
let request_body_ty = if self.lifetimes.body.is_empty() {
|
||||
quote! { RequestBody }
|
||||
} else {
|
||||
quote! { IncomingRequestBody }
|
||||
};
|
||||
|
||||
quote! {
|
||||
let request_body: <
|
||||
RequestBody #body_lifetimes
|
||||
as #ruma_common::serde::Outgoing
|
||||
>::Incoming = {
|
||||
let request_body: #request_body_ty = {
|
||||
let body = ::std::convert::AsRef::<[::std::primitive::u8]>::as_ref(
|
||||
request.body(),
|
||||
);
|
||||
|
@ -186,7 +186,7 @@ impl Request {
|
||||
#[cfg(feature = "client")]
|
||||
impl #impl_generics #ruma_common::api::OutgoingRequest for Request #ty_generics #where_clause {
|
||||
type EndpointError = #error_ty;
|
||||
type IncomingResponse = <Response as #ruma_common::serde::Outgoing>::Incoming;
|
||||
type IncomingResponse = Response;
|
||||
|
||||
const METADATA: #ruma_common::api::Metadata = self::METADATA;
|
||||
|
||||
|
@ -17,10 +17,7 @@ impl Response {
|
||||
|
||||
let typed_response_body_decl = self.has_body_fields().then(|| {
|
||||
quote! {
|
||||
let response_body: <
|
||||
ResponseBody
|
||||
as #ruma_common::serde::Outgoing
|
||||
>::Incoming = {
|
||||
let response_body: ResponseBody = {
|
||||
let body = ::std::convert::AsRef::<[::std::primitive::u8]>::as_ref(
|
||||
response.body(),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user