diff options
| author | Vincent Prouillet | 2020-06-09 21:29:50 +0200 | 
|---|---|---|
| committer | GitHub | 2020-06-09 21:29:50 +0200 | 
| commit | e052be5fdac051d005ab0e93c1016e4e8ac4ee00 (patch) | |
| tree | cc21f3b2461883c6147a267f49813545331fc6b8 /validator_derive | |
| parent | db4f4be938d381d4a83efbfbbcc1ac9b1a1df511 (diff) | |
| parent | f51e0d671880b32a574060c642e405c590dd0974 (diff) | |
| download | validator-e052be5fdac051d005ab0e93c1016e4e8ac4ee00.tar.bz2 | |
Merge pull request #102 from LucasPickering/blanket-ref-impl
Add a blanket Validate implementation for references
Diffstat (limited to 'validator_derive')
| -rw-r--r-- | validator_derive/tests/range.rs | 21 | 
1 files changed, 20 insertions, 1 deletions
| diff --git a/validator_derive/tests/range.rs b/validator_derive/tests/range.rs index 869510a..006d085 100644 --- a/validator_derive/tests/range.rs +++ b/validator_derive/tests/range.rs @@ -2,7 +2,7 @@  extern crate validator_derive;  extern crate validator; -use validator::Validate; +use validator::{Validate, ValidationErrors};  #[test]  fn can_validate_range_ok() { @@ -71,3 +71,22 @@ fn can_specify_message_for_range() {      assert_eq!(errs["val"].len(), 1);      assert_eq!(errs["val"][0].clone().message.unwrap(), "oops");  } + +#[test] +fn can_pass_reference_as_validate() { +    // This tests that the blanket Validate implementation on +    // `&T where T:Validate` works properly + +    #[derive(Validate)] +    struct TestStruct { +        #[validate(range(min = 100))] +        num_field: u32, +    } + +    fn validate<T: Validate>(value: T) -> Result<(), ValidationErrors> { +        value.validate() +    } + +    let val = TestStruct { num_field: 10 }; +    validate(&val).unwrap_err(); +} | 
