Skip to content

Commit 91f86de

Browse files
authored
[ISSUE #1476]♻️Refactor derive RequestHeaderCodec parse logic🔥 (#1478)
1 parent 4cce98b commit 91f86de

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

rocketmq-macros/src/request_header_custom.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ pub(super) fn request_header_codec_inner(
6565
&format!("{}", field_name).to_ascii_uppercase(),
6666
field_name.span(),
6767
);
68+
let type_name = if let Some(value) = &has_option {
69+
get_type_name(value)
70+
} else {
71+
get_type_name(&field.ty)
72+
};
6873
(
6974
quote! {
7075
const #static_name: &'static str = #camel_case_name;
7176
},
7277
(
73-
if let Some(value) = has_option {
74-
let type_name = get_type_name(value);
78+
if has_option.is_some() {
7579
if type_name == "CheetahString" {
7680
quote! {
7781
if let Some(ref value) = self.#field_name {
@@ -92,17 +96,15 @@ pub(super) fn request_header_codec_inner(
9296
}
9397
} else {
9498
quote! {
95-
if let Some(value) = self.#field_name {
99+
if let Some(ref value) = self.#field_name {
96100
map.insert (
97101
cheetah_string::CheetahString::from_static_str(Self::#static_name),
98102
cheetah_string::CheetahString::from_string(value.to_string())
99103
);
100104
}
101105
}
102106
}
103-
} else {
104-
let type_name = get_type_name(&field.ty);
105-
if type_name == "CheetahString" {
107+
} else if type_name == "CheetahString" {
106108
quote! {
107109
map.insert (
108110
cheetah_string::CheetahString::from_static_str(Self::#static_name),
@@ -124,10 +126,9 @@ pub(super) fn request_header_codec_inner(
124126
);
125127
}
126128
}
127-
},
129+
,
128130
// build FromMap impl
129131
if let Some(value) = has_option {
130-
let type_name = get_type_name(value);
131132
if type_name == "CheetahString" || type_name == "String" {
132133
if required {
133134
quote! {
@@ -161,7 +162,6 @@ pub(super) fn request_header_codec_inner(
161162
}
162163
} else {
163164
let types = &field.ty;
164-
let type_name = get_type_name(types);
165165
if type_name == "CheetahString" || type_name == "String" {
166166
if required {
167167
quote! {

0 commit comments

Comments
 (0)