Skip to content

Commit

Permalink
docs: update.
Browse files Browse the repository at this point in the history
  • Loading branch information
yassun7010 committed Jan 14, 2024
1 parent 6b8f6db commit 65da1b6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/src/Attributes/array_max_items.md
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());
```
17 changes: 17 additions & 0 deletions docs/src/Attributes/array_min_items.md
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());
```
2 changes: 1 addition & 1 deletion docs/src/Attributes/numeric_exclusive_maximum.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ struct Data (
assert!(Data(5).validate().is_ok());
assert!(Data(6).validate().is_err());
assert!(Data(7).validate().is_err());
```
```
24 changes: 24 additions & 0 deletions docs/src/Attributes/object_max_properties.md
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());
```
25 changes: 25 additions & 0 deletions docs/src/Attributes/object_min_properties.md
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());
```
4 changes: 4 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- [Numeric: "exclusive_maximum"](./Attributes/numeric_exclusive_maximum.md)
- [Numeric: "exclusive_minimum"](./Attributes/numeric_exclusive_minimum.md)
- [Numeric: "multiple_of"](./Attributes/numeric_multiple_of.md)
- [Object: "max_properties"](./Attributes/object_max_properties.md)
- [Object: "min_properties"](./Attributes/object_min_properties.md)
- [Array: "max_items"](./Attributes/array_max_items.md)
- [Array: "min_items"](./Attributes/array_min_items.md)
- [Nested validation](./Attributes/nested.md)
- [Custom Message](./Attributes/custom_message.md)
- [Trailt](./trait.md)
Expand Down

0 comments on commit 65da1b6

Please sign in to comment.