From e42b0f1c7f532144879b9ea409cc97eb79e30429 Mon Sep 17 00:00:00 2001 From: 3lpsy <8757851+3lpsy@users.noreply.github.com> Date: Sat, 8 Feb 2025 13:45:40 -0600 Subject: [PATCH] Add convenience with_error function --- validator/src/types.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/validator/src/types.rs b/validator/src/types.rs index 9bf49da6..6b328fa8 100644 --- a/validator/src/types.rs +++ b/validator/src/types.rs @@ -162,7 +162,13 @@ impl ValidationErrors { }) .collect::>() } + /// Add a field validation error to the struct, returning self + pub fn with_error(mut self, field: &'static str, error: ValidationError) -> ValidationErrors { + self.add(field, error); + self + } + /// Add a field validation error to the struct pub fn add(&mut self, field: &'static str, error: ValidationError) { if let ValidationErrorsKind::Field(ref mut vec) = self .0