Skip to content

Commit 668bcfa

Browse files
committed
Apply string casing to method params while deriving proxies and services
1 parent 18e779f commit 668bcfa

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

derive/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use darling::FromMeta;
55
use heck::{ToKebabCase, ToLowerCamelCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
66
use proc_macro2::{Literal, TokenStream};
77
use quote::{format_ident, quote};
8-
use syn::{Attribute, FnArg, Ident, Pat, Signature, Type};
8+
use syn::{spanned::Spanned, Attribute, FnArg, Ident, Pat, Signature, Type};
99

1010
use proxy::proxy_macro;
1111
use service::service_macro;
@@ -51,7 +51,7 @@ impl MethodAttributes {
5151

5252
pub(crate) struct RpcMethod<'a> {
5353
signature: &'a Signature,
54-
args: Vec<(&'a Ident, &'a Type)>,
54+
args: Vec<(Ident, &'a Type)>,
5555
method_name: String,
5656
method_name_literal: Literal,
5757
args_struct_ident: Ident,
@@ -75,7 +75,13 @@ impl<'a> RpcMethod<'a> {
7575
}
7676
FnArg::Typed(pat_type) => {
7777
let ident = match &*pat_type.pat {
78-
Pat::Ident(ty) => &ty.ident,
78+
Pat::Ident(ty) => {
79+
let fn_arg = rename_all
80+
.as_ref()
81+
.map(|r| r.rename(&ty.ident.to_string()))
82+
.unwrap_or(ty.ident.to_string());
83+
Ident::new(&fn_arg, ty.span().clone())
84+
}
7985
_ => panic!("Arguments must not be patterns."),
8086
};
8187
args.push((ident, &*pat_type.ty));
@@ -120,6 +126,7 @@ impl<'a> RpcMethod<'a> {
120126
let tokens = quote! {
121127
#[derive(Debug, ::serde::Serialize, ::serde::Deserialize)]
122128
#[allow(non_camel_case_types)]
129+
#[allow(non_snake_case)]
123130
struct #args_struct_ident {
124131
#(#struct_fields)*
125132
}
@@ -213,6 +220,7 @@ impl<'a> RpcMethod<'a> {
213220
};
214221

215222
quote! {
223+
#[allow(non_snake_case)]
216224
async fn #method_ident(&mut self, #(#method_args),*) #output {
217225
let args = #args_struct_ident {
218226
#(#struct_fields),*

0 commit comments

Comments
 (0)