优化代码,避免使用clone导致额外的内存占用

This commit is contained in:
李运家 2024-11-02 11:58:25 +08:00
parent 79fabc6bcc
commit 7b84948624

View File

@ -24,8 +24,8 @@ pub fn validate_params(params: &impl Validate, local: &str) -> ResResult<ResData
},
validator::ValidationErrorsKind::Field(err) => {
err.iter().for_each(|e| {
let msg = e.message.clone().unwrap_or_default();
errors.push(message!(local, MessageId::from_str(msg.trim()).unwrap()))
let msg = e.message.as_ref().unwrap();
errors.push(message!(local, MessageId::from_str(msg).unwrap()))
});
},
};
@ -38,8 +38,8 @@ pub fn validate_params(params: &impl Validate, local: &str) -> ResResult<ResData
fn pack_error_msg(errors: & mut Vec<&str>, raw_errors: &Box<ValidationErrors>, local: &str) {
for (_field, errs) in raw_errors.field_errors() {
for e in errs {
let msg = e.message.clone().unwrap_or_default();
errors.push(message!(local, MessageId::from_str(msg.trim()).unwrap()));
let msg = e.message.as_ref().unwrap();
errors.push(message!(local, MessageId::from_str(msg).unwrap()));
}
}
}