optimize hashmap insertion
This commit is contained in:
1 parent
f1533781a4
commit
1a9d1eda19
1 file changed
+15
-8
@@ -62,14 +62,21 @@ impl FormData {
|
|||||||
In this case we would want to deserialize the value as follows
|
In this case we would want to deserialize the value as follows
|
||||||
favourite_language: "rust"
|
favourite_language: "rust"
|
||||||
*/
|
*/
|
||||||
if values.len() > 1 {
|
parsed_values.insert(
|
||||||
// handling multiple values - case 1
|
fieldname,
|
||||||
parsed_values.insert(fieldname, ValueType::VecText(values.clone()));
|
if values.len() > 1 {
|
||||||
} else {
|
// handling multiple values - case 1
|
||||||
// handle single value - case 2
|
ValueType::VecText(values)
|
||||||
let prepared_value = values.into_iter().next().unwrap();
|
} else {
|
||||||
parsed_values.insert(fieldname, ValueType::Text(prepared_value));
|
// handle single value - case 2
|
||||||
}
|
ValueType::Text(
|
||||||
|
values
|
||||||
|
.into_iter()
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| serde_json::Error::custom("Values array is empty"))?,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert HashMap to JSON string
|
// convert HashMap to JSON string
|
||||||
|
|||||||
Reference in new issue
Block a user