aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--validator/Cargo.toml2
-rw-r--r--validator/src/types.rs13
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 <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) {