From af6e65d216e2742ecf72b323596c62d62bcf27bd Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 00:15:39 +0900 Subject: [PATCH 1/9] feat: support FnOnce -> Result<(), Vec>. --- serde_valid/src/lib.rs | 12 --- serde_valid/src/validation.rs | 1 + serde_valid/src/validation/custom.rs | 74 ++++++++++++++++ serde_valid/tests/custom_test.rs | 87 +++++++++++++++++++ .../struct_validate/generic/custom.rs | 12 +-- .../variant_validate/generic/custom.rs | 8 +- 6 files changed, 172 insertions(+), 22 deletions(-) create mode 100644 serde_valid/src/validation/custom.rs diff --git a/serde_valid/src/lib.rs b/serde_valid/src/lib.rs index 6d6b73c..e1dcb73 100644 --- a/serde_valid/src/lib.rs +++ b/serde_valid/src/lib.rs @@ -656,18 +656,6 @@ where pub use serde_valid_derive::Validate; -#[doc(hidden)] -pub mod helpers { - /// This function is used to avoid [rustc(E0282)](https://doc.rust-lang.org/error_codes/E0282.html) error in `#[validate(custom)]` validator on the struct. - #[inline] - pub fn wrap_closure_validation( - data: &T, - f: impl FnOnce(&T) -> Result<(), crate::validation::Error>, - ) -> Result<(), crate::validation::Error> { - f(data) - } -} - #[cfg(test)] pub mod tests { pub type Result = std::result::Result>; diff --git a/serde_valid/src/validation.rs b/serde_valid/src/validation.rs index c0d6f04..25b6865 100644 --- a/serde_valid/src/validation.rs +++ b/serde_valid/src/validation.rs @@ -1,5 +1,6 @@ mod array; mod composited; +pub mod custom; pub mod error; mod generic; mod numeric; diff --git a/serde_valid/src/validation/custom.rs b/serde_valid/src/validation/custom.rs new file mode 100644 index 0000000..a0dbb72 --- /dev/null +++ b/serde_valid/src/validation/custom.rs @@ -0,0 +1,74 @@ +/// This function is used to avoid [rustc(E0282)](https://doc.rust-lang.org/error_codes/E0282.html) error in `#[validate(custom)]` validator on the struct. +#[inline] +pub fn wrap_closure_validation( + data: T, + f: impl FnOnce(T) -> Result<(), M>, +) -> Result<(), Vec> { + f(data).map_err(|e| e.to_multiple()) +} + +pub trait ToMultiple { + fn to_multiple(self) -> Vec; +} + +impl ToMultiple for Vec { + fn to_multiple(self) -> Vec { + self + } +} + +impl ToMultiple for crate::validation::Error { + fn to_multiple(self) -> Vec { + vec![self] + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_custom_fn_single_error() { + fn single_error(data: &i32) -> Result<(), crate::validation::Error> { + if *data > 0 { + Ok(()) + } else { + Err(crate::validation::Error::Custom( + "Value must be greater than 0".to_string(), + )) + } + } + + assert!(wrap_closure_validation(&1i32, single_error).is_ok()); + } + + #[test] + fn test_custom_fn_multiple_errors() { + fn multiple_errors(data: &i32) -> Result<(), Vec> { + let mut errors = Vec::new(); + if *data > 0 { + return Ok(()); + } else { + errors.push(crate::validation::Error::Custom( + "Value must be greater than 0".to_string(), + )); + } + + if *data < 10 { + return Ok(()); + } else { + errors.push(crate::validation::Error::Custom( + "Value must be less than 10".to_string(), + )); + } + + if errors.is_empty() { + Ok(()) + } else { + Err(errors) + } + } + + assert!(wrap_closure_validation(&1i32, multiple_errors).is_ok()); + } +} diff --git a/serde_valid/tests/custom_test.rs b/serde_valid/tests/custom_test.rs index 300b725..7b1e73f 100644 --- a/serde_valid/tests/custom_test.rs +++ b/serde_valid/tests/custom_test.rs @@ -192,3 +192,90 @@ fn unnamed_struct_custom_closure_is_err() { assert_eq!(s.0, 5); assert!(s.validate().is_err()); } + +#[test] +fn named_struct_custom_vec_errors_is_ok() { + fn validation(_val: &TestStruct) -> Result<(), Vec> { + Ok(()) + } + + #[derive(Validate)] + #[validate(custom(validation))] + struct TestStruct { + val: i32, + } + + let s = TestStruct { val: 5 }; + assert_eq!(s.val, 5); + assert!(s.validate().is_ok()); +} + +#[test] +fn named_struct_custom_vec_errors_is_err() { + fn validation(_val: &TestStruct) -> Result<(), Vec> { + Err(vec![ + serde_valid::validation::Error::Custom("Error 1".to_owned()), + serde_valid::validation::Error::Custom("Error 2".to_owned()), + ]) + } + + #[derive(Validate)] + #[validate(custom(validation))] + struct TestStruct { + val: i32, + } + + let s = TestStruct { val: 5 }; + + assert_eq!(s.val, 5); + assert_eq!( + s.validate().unwrap_err().to_string(), + json!({ + "errors": ["Error 1", "Error 2"], + }) + .to_string() + ); +} + +#[test] +fn named_struct_custom_closure_vec_errors_is_ok() { + fn sample_struct_validation(_val: i32) -> Result<(), Vec> { + Ok(()) + } + + #[derive(Validate)] + #[validate(custom(|s| sample_struct_validation(s.val)))] + struct TestStruct { + val: i32, + } + + let s = TestStruct { val: 5 }; + assert_eq!(s.val, 5); + assert!(s.validate().is_ok()); +} + +#[test] +fn named_struct_custom_closure_vec_errors_is_err() { + fn sample_struct_validation(_val: i32) -> Result<(), Vec> { + Err(vec![ + serde_valid::validation::Error::Custom("Error 1".to_owned()), + serde_valid::validation::Error::Custom("Error 2".to_owned()), + ]) + } + + #[derive(Validate)] + #[validate(custom(|s| sample_struct_validation(s.val)))] + struct TestStruct { + val: i32, + } + + let s = TestStruct { val: 5 }; + assert_eq!(s.val, 5); + assert_eq!( + s.validate().unwrap_err().to_string(), + json!({ + "errors": ["Error 1", "Error 2"], + }) + .to_string() + ); +} diff --git a/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs b/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs index f4167ba..833036c 100644 --- a/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs +++ b/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs @@ -53,8 +53,8 @@ fn extract_struct_custom_from_meta_path(meta_path: &syn::Path) -> Result Result { Ok(quote!( - if let Err(__error) = serde_valid::helpers::wrap_closure_validation(self, #meta_list) { - __rule_vec_errors.push(__error); + if let Err(__errors) = serde_valid::validation::custom::wrap_closure_validation(self, #meta_list) { + __rule_vec_errors.extend(__errors); }; )) } @@ -73,8 +73,8 @@ fn extract_struct_custom_from_closure( closure: &syn::ExprClosure, ) -> Result { Ok(quote!( - if let Err(__error) = serde_valid::helpers::wrap_closure_validation(self, #closure) { - __rule_vec_errors.push(__error); + if let Err(__errors) = serde_valid::validation::custom::wrap_closure_validation(self, #closure) { + __rule_vec_errors.extend(__errors); }; )) } diff --git a/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs b/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs index 46d0b8f..9386f08 100644 --- a/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs +++ b/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs @@ -55,8 +55,8 @@ fn extract_variant_custom_from_meta_path( let rule_fn_name = &meta_path; Ok(quote!( - if let Err(__error) = #rule_fn_name(self) { - __rule_vec_errors.push(__error); + if let Err(__errors) = serde_valid::validation::custom::wrap_closure_validation(self, #rule_fn_name) { + __rule_vec_errors.extend(__errors); }; )) } @@ -65,8 +65,8 @@ fn extract_variant_custom_from_meta_list( meta_list: &syn::MetaList, ) -> Result { Ok(quote!( - if let Err(__error) = serde_valid::helpers::wrap_closure_validation(self, #meta_list) { - __rule_vec_errors.push(__error); + if let Err(__errors) = serde_valid::validation::custom::wrap_closure_validation(self, #meta_list) { + __rule_vec_errors.extend(__errors); }; )) } From 4c8b59ad16966936b6e5ada04de6e575bad0957f Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 00:18:29 +0900 Subject: [PATCH 2/9] chore: rename trait. --- serde_valid/src/validation/custom.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/serde_valid/src/validation/custom.rs b/serde_valid/src/validation/custom.rs index a0dbb72..6b838ae 100644 --- a/serde_valid/src/validation/custom.rs +++ b/serde_valid/src/validation/custom.rs @@ -1,24 +1,24 @@ /// This function is used to avoid [rustc(E0282)](https://doc.rust-lang.org/error_codes/E0282.html) error in `#[validate(custom)]` validator on the struct. #[inline] -pub fn wrap_closure_validation( +pub fn wrap_closure_validation( data: T, f: impl FnOnce(T) -> Result<(), M>, ) -> Result<(), Vec> { - f(data).map_err(|e| e.to_multiple()) + f(data).map_err(|e| e.into_vec_errors()) } -pub trait ToMultiple { - fn to_multiple(self) -> Vec; +pub trait IntoVecErrors { + fn into_vec_errors(self) -> Vec; } -impl ToMultiple for Vec { - fn to_multiple(self) -> Vec { +impl IntoVecErrors for Vec { + fn into_vec_errors(self) -> Vec { self } } -impl ToMultiple for crate::validation::Error { - fn to_multiple(self) -> Vec { +impl IntoVecErrors for crate::validation::Error { + fn into_vec_errors(self) -> Vec { vec![self] } } From e9f899b625a5a63f55c69116481ee30ab17921ae Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 00:19:20 +0900 Subject: [PATCH 3/9] fix: ci. --- serde_valid/tests/custom_test.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serde_valid/tests/custom_test.rs b/serde_valid/tests/custom_test.rs index 7b1e73f..6ddf234 100644 --- a/serde_valid/tests/custom_test.rs +++ b/serde_valid/tests/custom_test.rs @@ -232,6 +232,7 @@ fn named_struct_custom_vec_errors_is_err() { s.validate().unwrap_err().to_string(), json!({ "errors": ["Error 1", "Error 2"], + "properties": {} }) .to_string() ); @@ -275,6 +276,7 @@ fn named_struct_custom_closure_vec_errors_is_err() { s.validate().unwrap_err().to_string(), json!({ "errors": ["Error 1", "Error 2"], + "properties": {} }) .to_string() ); From 2fa3ddfbeeeee5c7718a6989a1f112e560b6f5b9 Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 23:16:13 +0900 Subject: [PATCH 4/9] feat: add readme and add test cases. --- serde_valid/README.md | 41 +++++++++++++++++++ serde_valid/src/lib.rs | 41 +++++++++++++++++++ serde_valid/src/validation/custom.rs | 13 ++++-- .../field_validate/generic/custom.rs | 4 +- .../variant_validate/generic/custom.rs | 4 +- 5 files changed, 96 insertions(+), 7 deletions(-) diff --git a/serde_valid/README.md b/serde_valid/README.md index 8f0b1ed..e1fa270 100644 --- a/serde_valid/README.md +++ b/serde_valid/README.md @@ -265,6 +265,47 @@ let s = Data { assert!(s.validate().is_ok()); ``` +## Multi Errors Validation +If you want to return multiple errors in the use custom validation method, you can use `#[validate(custom)]` same as single error. + +```rust +use serde_valid::Validate; + +fn user_validation(_val: &i32) -> Result<(), Vec> { // <-- Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! + Ok(()) +} + +#[derive(Validate)] +struct Data { + #[validate(custom(user_validation))] + val: i32, +} + +let s = Data { val: 1 }; + +assert!(s.validate().is_ok()); +``` + +And you can also use closure. + +```rust +use serde_valid::Validate; + +fn user_validation(_val: &i32, param1: bool) -> Result<(), serde_valid::validation::Error> { + Ok(()) +} + +#[derive(Validate)] +struct Data { + #[validate(custom(|v| user_validation(v, true)))] + val: i32, +} + +let s = Data { val: 1 }; + +assert!(s.validate().is_ok()); +``` + ## Multi Fields Validation ### Custom Validation Now, you can use `#[validate(custom)]` for multi fields validation. diff --git a/serde_valid/src/lib.rs b/serde_valid/src/lib.rs index e1dcb73..277aeba 100644 --- a/serde_valid/src/lib.rs +++ b/serde_valid/src/lib.rs @@ -275,6 +275,47 @@ //! assert!(s.validate().is_ok()); //! ``` //! +//! ## Multi Errors Validation +//! If you want to return multiple errors in the use custom validation method, you can use `#[validate(custom)]` same as single error. +//! +//! ```rust +//! use serde_valid::Validate; +//! +//! fn user_validation(_val: &i32) -> Result<(), Vec> { // <-- Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! +//! Ok(()) +//! } +//! +//! #[derive(Validate)] +//! struct Data { +//! #[validate(custom(user_validation))] +//! val: i32, +//! } +//! +//! let s = Data { val: 1 }; +//! +//! assert!(s.validate().is_ok()); +//! ``` +//! +//! And you can also use closure. +//! +//! ```rust +//! use serde_valid::Validate; +//! +//! fn user_validation(_val: &i32, param1: bool) -> Result<(), serde_valid::validation::Error> { +//! Ok(()) +//! } +//! +//! #[derive(Validate)] +//! struct Data { +//! #[validate(custom(|v| user_validation(v, true)))] +//! val: i32, +//! } +//! +//! let s = Data { val: 1 }; +//! +//! assert!(s.validate().is_ok()); +//! ``` +//! //! ## Multi Fields Validation //! ### Custom Validation //! Now, you can use `#[validate(custom)]` for multi fields validation. diff --git a/serde_valid/src/validation/custom.rs b/serde_valid/src/validation/custom.rs index 6b838ae..1f1f3ee 100644 --- a/serde_valid/src/validation/custom.rs +++ b/serde_valid/src/validation/custom.rs @@ -1,12 +1,19 @@ /// This function is used to avoid [rustc(E0282)](https://doc.rust-lang.org/error_codes/E0282.html) error in `#[validate(custom)]` validator on the struct. #[inline] -pub fn wrap_closure_validation( - data: T, - f: impl FnOnce(T) -> Result<(), M>, +pub fn wrap_closure_validation( + data: &T, + f: impl FnOnce(&T) -> Result<(), M>, ) -> Result<(), Vec> { f(data).map_err(|e| e.into_vec_errors()) } +#[inline] +pub fn wrap_into_vec_errors( + result: Result<(), M>, +) -> Result<(), Vec> { + result.map_err(|e| e.into_vec_errors()) +} + pub trait IntoVecErrors { fn into_vec_errors(self) -> Vec; } diff --git a/serde_valid_derive/src/attribute/field_validate/generic/custom.rs b/serde_valid_derive/src/attribute/field_validate/generic/custom.rs index 6627a19..eb8ad72 100644 --- a/serde_valid_derive/src/attribute/field_validate/generic/custom.rs +++ b/serde_valid_derive/src/attribute/field_validate/generic/custom.rs @@ -35,11 +35,11 @@ pub fn extract_generic_custom_validator( }?; Ok(quote!( - if let Err(__error) = #custom_fn_name(#field_ident) { + if let Err(__errors) = serde_valid::validation::custom::wrap_into_vec_errors(#custom_fn_name(#field_ident)) { #errors .entry(#rename) .or_default() - .push(__error); + .extend(__errors); }; )) } diff --git a/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs b/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs index 9386f08..8223f78 100644 --- a/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs +++ b/serde_valid_derive/src/attribute/variant_validate/generic/custom.rs @@ -75,8 +75,8 @@ fn extract_variant_custom_from_closure( closure: &syn::ExprClosure, ) -> Result { Ok(quote!( - if let Err(__error) = serde_valid::helpers::wrap_closure_validation(self, #closure) { - __rule_vec_errors.push(__error); + if let Err(__errors) = serde_valid::validation::custom::wrap_closure_validation(self, #closure) { + __rule_vec_errors.extend(__errors); }; )) } From 22629d96db5c5dc618688cd616c96812ec37d261 Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 23:19:40 +0900 Subject: [PATCH 5/9] refactor: change wrapper. --- .../src/attribute/struct_validate/generic/custom.rs | 2 +- .../src/attribute/variant_validate/generic/custom.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs b/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs index 833036c..0a8a8e8 100644 --- a/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs +++ b/serde_valid_derive/src/attribute/struct_validate/generic/custom.rs @@ -53,7 +53,7 @@ fn extract_struct_custom_from_meta_path(meta_path: &syn::Path) -> Result Date: Thu, 20 Jun 2024 23:24:13 +0900 Subject: [PATCH 6/9] docs: update. --- serde_valid/README.md | 9 ++++----- serde_valid/src/lib.rs | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/serde_valid/README.md b/serde_valid/README.md index e1fa270..64a93ed 100644 --- a/serde_valid/README.md +++ b/serde_valid/README.md @@ -200,8 +200,8 @@ assert_eq!( ); ``` -## Custom Method - +## Custom Validation +### Single Error Validation You can use your custom validation using by `#[validate(custom)]`. ```rust @@ -265,7 +265,7 @@ let s = Data { assert!(s.validate().is_ok()); ``` -## Multi Errors Validation +### Multi Errors Validation If you want to return multiple errors in the use custom validation method, you can use `#[validate(custom)]` same as single error. ```rust @@ -306,8 +306,7 @@ let s = Data { val: 1 }; assert!(s.validate().is_ok()); ``` -## Multi Fields Validation -### Custom Validation +### Multi Fields Validation Now, you can use `#[validate(custom)]` for multi fields validation. ```rust diff --git a/serde_valid/src/lib.rs b/serde_valid/src/lib.rs index 277aeba..1d96ee8 100644 --- a/serde_valid/src/lib.rs +++ b/serde_valid/src/lib.rs @@ -210,8 +210,8 @@ //! # } //! ``` //! -//! ## Custom Method -//! +//! ## Custom Validation +//! ### Single Error Validation //! You can use your custom validation using by `#[validate(custom)]`. //! //! ```rust @@ -275,7 +275,7 @@ //! assert!(s.validate().is_ok()); //! ``` //! -//! ## Multi Errors Validation +//! ### Multi Errors Validation //! If you want to return multiple errors in the use custom validation method, you can use `#[validate(custom)]` same as single error. //! //! ```rust @@ -316,8 +316,7 @@ //! assert!(s.validate().is_ok()); //! ``` //! -//! ## Multi Fields Validation -//! ### Custom Validation +//! ### Multi Fields Validation //! Now, you can use `#[validate(custom)]` for multi fields validation. //! //! ```rust From 3366c4f3b4a0cfb172a463c87b5f3b69178bdbc0 Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 23:25:22 +0900 Subject: [PATCH 7/9] docs: update. --- serde_valid/README.md | 3 ++- serde_valid/src/lib.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/serde_valid/README.md b/serde_valid/README.md index 64a93ed..23de635 100644 --- a/serde_valid/README.md +++ b/serde_valid/README.md @@ -271,7 +271,8 @@ If you want to return multiple errors in the use custom validation method, you c ```rust use serde_valid::Validate; -fn user_validation(_val: &i32) -> Result<(), Vec> { // <-- Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! +// Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! 🚀 +fn user_validation(_val: &i32) -> Result<(), Vec> { Ok(()) } diff --git a/serde_valid/src/lib.rs b/serde_valid/src/lib.rs index 1d96ee8..a9cfcde 100644 --- a/serde_valid/src/lib.rs +++ b/serde_valid/src/lib.rs @@ -281,7 +281,8 @@ //! ```rust //! use serde_valid::Validate; //! -//! fn user_validation(_val: &i32) -> Result<(), Vec> { // <-- Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! +//! // Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! 🚀 +//! fn user_validation(_val: &i32) -> Result<(), Vec> { //! Ok(()) //! } //! From e28b4de32aab9c1b40ed7119bf21796c5faf9fca Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 23:26:04 +0900 Subject: [PATCH 8/9] docs: update. --- serde_valid/README.md | 2 +- serde_valid/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/serde_valid/README.md b/serde_valid/README.md index 23de635..7bb2d79 100644 --- a/serde_valid/README.md +++ b/serde_valid/README.md @@ -271,7 +271,7 @@ If you want to return multiple errors in the use custom validation method, you c ```rust use serde_valid::Validate; -// Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! 🚀 +// 🚀 Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! fn user_validation(_val: &i32) -> Result<(), Vec> { Ok(()) } diff --git a/serde_valid/src/lib.rs b/serde_valid/src/lib.rs index a9cfcde..6321f8a 100644 --- a/serde_valid/src/lib.rs +++ b/serde_valid/src/lib.rs @@ -281,7 +281,7 @@ //! ```rust //! use serde_valid::Validate; //! -//! // Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! 🚀 +//! // 🚀 Just change the return type from `Result<(), Error>` to `Result<(), Vec>` !! //! fn user_validation(_val: &i32) -> Result<(), Vec> { //! Ok(()) //! } From 51ef5effcd0e3599c675663acaaf4023fdc4fd6e Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Thu, 20 Jun 2024 23:26:43 +0900 Subject: [PATCH 9/9] update: docs. --- serde_valid/README.md | 20 -------------------- serde_valid/src/lib.rs | 20 -------------------- 2 files changed, 40 deletions(-) diff --git a/serde_valid/README.md b/serde_valid/README.md index 7bb2d79..272721f 100644 --- a/serde_valid/README.md +++ b/serde_valid/README.md @@ -287,26 +287,6 @@ let s = Data { val: 1 }; assert!(s.validate().is_ok()); ``` -And you can also use closure. - -```rust -use serde_valid::Validate; - -fn user_validation(_val: &i32, param1: bool) -> Result<(), serde_valid::validation::Error> { - Ok(()) -} - -#[derive(Validate)] -struct Data { - #[validate(custom(|v| user_validation(v, true)))] - val: i32, -} - -let s = Data { val: 1 }; - -assert!(s.validate().is_ok()); -``` - ### Multi Fields Validation Now, you can use `#[validate(custom)]` for multi fields validation. diff --git a/serde_valid/src/lib.rs b/serde_valid/src/lib.rs index 6321f8a..12cb1e7 100644 --- a/serde_valid/src/lib.rs +++ b/serde_valid/src/lib.rs @@ -297,26 +297,6 @@ //! assert!(s.validate().is_ok()); //! ``` //! -//! And you can also use closure. -//! -//! ```rust -//! use serde_valid::Validate; -//! -//! fn user_validation(_val: &i32, param1: bool) -> Result<(), serde_valid::validation::Error> { -//! Ok(()) -//! } -//! -//! #[derive(Validate)] -//! struct Data { -//! #[validate(custom(|v| user_validation(v, true)))] -//! val: i32, -//! } -//! -//! let s = Data { val: 1 }; -//! -//! assert!(s.validate().is_ok()); -//! ``` -//! //! ### Multi Fields Validation //! Now, you can use `#[validate(custom)]` for multi fields validation. //!