From 934868df42ba5ebfc91fa3b1b1ec45f47a27e34c Mon Sep 17 00:00:00 2001 From: Joel Wachsler Date: Tue, 12 Jul 2022 13:38:10 +0000 Subject: [PATCH] Simplify borrow building --- .../group/method/method_with_params.rs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/qbittorrent-web-api-gen/src/generate/group/method/method_with_params.rs b/qbittorrent-web-api-gen/src/generate/group/method/method_with_params.rs index 26372ce..591b164 100644 --- a/qbittorrent-web-api-gen/src/generate/group/method/method_with_params.rs +++ b/qbittorrent-web-api-gen/src/generate/group/method/method_with_params.rs @@ -63,23 +63,21 @@ pub fn create_method_with_params( let name = util::to_ident(&n.to_snake()); let t = util::to_ident(¶m.to_borrowed_type()); - let method = if param.should_borrow() { - quote! { - pub fn #name(mut self, value: &#t) -> Self { - self.form = self.form.text(#n, value.to_string()); - self - } - } + let builder_param = if param.should_borrow() { + quote! { &#t } } else { - quote! { - pub fn #name(mut self, value: #t) -> Self { - self.form = self.form.text(#n, value.to_string()); - self - } - } + quote! { #t } }; - util::add_docs(¶m.get_type_info().description, method) + util::add_docs( + ¶m.get_type_info().description, + quote! { + pub fn #name(mut self, value: #builder_param) -> Self { + self.form = self.form.text(#n, value.to_string()); + self + } + }, + ) }); let group_name = util::to_ident(&group.name.to_camel());