Simplify request path deserialization by removing RequestPath struct

This commit is contained in:
Jonas Platte 2020-02-18 21:05:21 +01:00
parent 9e076858af
commit 8e7325cdcc
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 1 additions and 32 deletions

View File

@ -117,14 +117,12 @@ impl ToTokens for Api {
"number of declared path parameters needs to match amount of placeholders in path"
);
let request_path_init_fields = self.request.request_path_init_fields();
let path_segments = path_str[1..].split('/');
let path_segment_push = path_segments.clone().map(|segment| {
let arg = if segment.starts_with(':') {
let path_var = &segment[1..];
let path_var_ident = Ident::new(path_var, Span::call_site());
quote!(&request_path.#path_var_ident.to_string())
quote!(&request.#path_var_ident.to_string())
} else {
quote!(#segment)
};
@ -135,10 +133,6 @@ impl ToTokens for Api {
});
let set_tokens = quote! {
let request_path = RequestPath {
#request_path_init_fields
};
// This `unwrap()` can only fail when the url is a
// cannot-be-base url like `mailto:` or `data:`, which is not
// the case for our placeholder url.

View File

@ -137,11 +137,6 @@ impl Request {
self.struct_init_fields(RequestFieldKind::Body, quote!(request))
}
/// Produces code for a struct initializer for path fields on a variable named `request`.
pub fn request_path_init_fields(&self) -> TokenStream {
self.struct_init_fields(RequestFieldKind::Path, quote!(request))
}
/// Produces code for a struct initializer for query string fields on a variable named `request`.
pub fn request_query_init_fields(&self) -> TokenStream {
self.struct_init_fields(RequestFieldKind::Query, quote!(request))
@ -348,20 +343,6 @@ impl ToTokens for Request {
}
});
let request_path_struct = if self.has_path_fields() {
let fields = self.fields.iter().filter_map(RequestField::as_path_field);
quote! {
/// Data in the request path.
#[derive(Debug)]
struct RequestPath {
#(#fields),*
}
}
} else {
TokenStream::new()
};
let request_query_struct = if let Some(f) = self.query_map_field() {
let field = Field { ident: None, colon_token: None, ..f.clone() };
@ -398,7 +379,6 @@ impl ToTokens for Request {
pub struct Request #request_def
#request_body_struct
#request_path_struct
#request_query_struct
};
@ -493,11 +473,6 @@ impl RequestField {
self.field_of_kind(RequestFieldKind::NewtypeRawBody)
}
/// Return the contained field if this request field is a path kind.
fn as_path_field(&self) -> Option<&Field> {
self.field_of_kind(RequestFieldKind::Path)
}
/// Return the contained field if this request field is a query kind.
fn as_query_field(&self) -> Option<&Field> {
self.field_of_kind(RequestFieldKind::Query)