diff options
| author | Vincent Prouillet | 2019-05-01 20:43:37 +0200 | 
|---|---|---|
| committer | Vincent Prouillet | 2019-05-01 20:43:39 +0200 | 
| commit | f33a34c6ed2d76ce6569a6bc40517ce9a69271d3 (patch) | |
| tree | add0744b86f2e3b705d66c64695f3c5e1177db3f | |
| parent | 4b9fe3939b106c151bff11e490a41212559f9a4a (diff) | |
| download | validator-f33a34c6ed2d76ce6569a6bc40517ce9a69271d3.tar.bz2 | |
Do not consume self when getting errors
Close #65
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | validator/Cargo.toml | 2 | ||||
| -rw-r--r-- | validator/src/types.rs | 13 | 
3 files changed, 12 insertions, 7 deletions
| @@ -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 <prouillet.vincent@gmail.com"]  license = "MIT"  description = "Common validation functions (email, url, length, ...) and trait - to be used with `validator_derive`" diff --git a/validator/src/types.rs b/validator/src/types.rs index 77033d9..2d79477 100644 --- a/validator/src/types.rs +++ b/validator/src/types.rs @@ -109,21 +109,22 @@ impl ValidationErrors {      /// Returns a map of field-level validation errors found for the struct that was validated and      /// any of it's nested structs that are tagged for validation. -    pub fn errors(self) -> 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<ValidationError>> { +    pub fn field_errors(&self) -> HashMap<&str, &Vec<ValidationError>> {          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::<HashMap<_,_>>()      }      pub fn add(&mut self, field: &'static str, error: ValidationError) { | 
