-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b8f6db
commit 65da1b6
Showing
6 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Array: "max_items" validation | ||
|
||
The `#[validate(max_items = ???)]` attribute is used to determine the maximum number of items in an array. | ||
|
||
```rust | ||
# extern crate serde_valid; | ||
use serde_valid::Validate; | ||
|
||
#[derive(Validate)] | ||
struct Data( | ||
#[validate(max_items = 2)] | ||
Vec<u8>, | ||
); | ||
|
||
assert!(Data(vec![1, 2]).validate().is_ok()); | ||
assert!(Data(vec![1, 2, 3]).validate().is_err()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Array: "min_items" validation | ||
|
||
The `#[validate(min_items = ???)]` attribute is used to determine the minimum number of items in an array. | ||
|
||
```rust | ||
# extern crate serde_valid; | ||
use serde_valid::Validate; | ||
|
||
#[derive(Validate)] | ||
struct Data( | ||
#[validate(min_items = 3)] | ||
Vec<u8>, | ||
); | ||
|
||
assert!(Data(vec![1, 2]).validate().is_err()); | ||
assert!(Data(vec![1, 2, 3]).validate().is_ok()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Object: "max_properties" validation | ||
|
||
The `#[validate(max_properties = ???)]` attribute is used to determine the maximum number of properties allowed in a map. | ||
|
||
```rust | ||
# extern crate serde_valid; | ||
use serde_valid::Validate; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Validate)] | ||
struct Data( | ||
#[validate(max_properties = 2)] | ||
HashMap<String, String>, | ||
); | ||
|
||
let mut map = HashMap::new(); | ||
map.insert("key1".to_string(), "value1".to_string()); | ||
map.insert("key2".to_string(), "value2".to_string()); | ||
|
||
assert!(Data(map.clone()).validate().is_ok()); | ||
|
||
map.insert("key3".to_string(), "value3".to_string()); | ||
assert!(Data(map.clone()).validate().is_err()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Object: "min_properties" validation | ||
|
||
The `#[validate(min_properties = ???)]` attribute is used to determine the minimum number of properties allowed in a map. | ||
|
||
```rust | ||
# extern crate serde_valid; | ||
use serde_valid::Validate; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Validate)] | ||
struct Data( | ||
#[validate(min_properties = 3)] | ||
HashMap<String, String>, | ||
); | ||
|
||
let mut map = HashMap::new(); | ||
map.insert("key1".to_string(), "value1".to_string()); | ||
map.insert("key2".to_string(), "value2".to_string()); | ||
|
||
assert!(Data(map.clone()).validate().is_err()); | ||
|
||
map.insert("key3".to_string(), "value3".to_string()); | ||
|
||
assert!(Data(map.clone()).validate().is_ok()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters