From f33a34c6ed2d76ce6569a6bc40517ce9a69271d3 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 1 May 2019 20:43:37 +0200 Subject: Do not consume self when getting errors Close #65 --- README.md | 4 ++++ validator/Cargo.toml | 2 +- validator/src/types.rs | 13 +++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c9bda8d..145c74c 100644 --- a/README.md +++ b/README.md @@ -298,6 +298,10 @@ For example, the following attributes all work: ### validator +#### 0.9.0 (2019/05/01) + +- `ValidationErrors::errors` and `ValidationErrors::field_errors` now use `&self` instead of `self` + #### 0.8.0 (2018/09/19) - Change error type to allow use with nested validation diff --git a/validator/Cargo.toml b/validator/Cargo.toml index f107fbb..dd184a0 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "validator" -version = "0.8.0" +version = "0.9.0" authors = ["Vincent Prouillet HashMap<&'static str, ValidationErrorsKind> { - self.0 + pub fn errors(&self) -> &HashMap<&'static str, ValidationErrorsKind> { + &self.0 } /// Returns a map of only field-level validation errors found for the struct that was validated. - pub fn field_errors(self) -> HashMap<&'static str, Vec> { + pub fn field_errors(&self) -> HashMap<&str, &Vec> { self.0 - .into_iter() + .iter() .filter_map(|(k, v)| { if let ValidationErrorsKind::Field(errors) = v { - Some((k, errors)) + Some((*k, errors)) } else { None } - }).collect() + }) + .collect::>() } pub fn add(&mut self, field: &'static str, error: ValidationError) { -- cgit v1.2.3