Skip to content

Commit 029e2db

Browse files
Merge #470
470: refactor: use iterator instead for-loop r=bidoubiwa a=bestgopher # Pull Request ## Related issue Fixes #<issue_number> ## What does this PR do? - ... ## PR checklist Please check if your PR fulfills the following requirements: - [ ] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [ ] Have you read the contributing guidelines? - [ ] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: bestgopher <[email protected]>
2 parents 4eaa5a7 + d31c8fd commit 029e2db

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/search.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,19 @@ fn serialize_attributes_to_crop_with_wildcard<S: Serializer>(
103103
match data {
104104
Some(Selectors::All) => ["*"].serialize(s),
105105
Some(Selectors::Some(data)) => {
106-
let mut results = Vec::new();
107-
for (name, value) in data.iter() {
108-
let mut result = String::new();
109-
result.push_str(name);
110-
if let Some(value) = value {
111-
result.push(':');
112-
result.push_str(value.to_string().as_str());
113-
}
114-
results.push(result)
115-
}
106+
let results = data
107+
.iter()
108+
.map(|(name, value)| {
109+
let mut result = String::new();
110+
result.push_str(name);
111+
if let Some(value) = value {
112+
result.push(':');
113+
result.push_str(value.to_string().as_str());
114+
}
115+
result
116+
})
117+
.collect::<Vec<_>>();
118+
116119
results.serialize(s)
117120
}
118121
None => s.serialize_none(),

0 commit comments

Comments
 (0)