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 535e2e3 commit 4e08245
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 43 deletions.
14 changes: 7 additions & 7 deletions docs/src/Attributes/numeric_exclusive_maximum.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# "exclusive_maximum" validation
# Numeric: "exclusive_maximum" validation

The `#[validate(exclusive_maximum = ???)]` attribute is used to validate that a number is greater than a given value.

Expand All @@ -7,12 +7,12 @@ The `#[validate(exclusive_maximum = ???)]` attribute is used to validate that a
use serde_valid::Validate;

#[derive(Validate)]
struct SampleStruct {
struct Data (
#[validate(exclusive_maximum = 6)]
val: i32,
}
i32
);

assert!(SampleStruct { val: 5 }.validate().is_ok());
assert!(SampleStruct { val: 6 }.validate().is_err());
assert!(SampleStruct { val: 7 }.validate().is_err());
assert!(Data(5).validate().is_ok());
assert!(Data(6).validate().is_err());
assert!(Data(7).validate().is_err());
```
14 changes: 7 additions & 7 deletions docs/src/Attributes/numeric_exclusive_minimum.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# "exclusive_minimum" validation
# Numeric: "exclusive_minimum" validation

The `#[validate(exclusive_minimum = ???)]` attribute is used to validate that a number is greater than a given value.

Expand All @@ -7,12 +7,12 @@ The `#[validate(exclusive_minimum = ???)]` attribute is used to validate that a
use serde_valid::Validate;

#[derive(Validate)]
struct SampleStruct {
struct Data (
#[validate(exclusive_minimum = 2)]
val: i32,
}
i32
);

assert!(SampleStruct { val: 1 }.validate().is_err());
assert!(SampleStruct { val: 2 }.validate().is_err());
assert!(SampleStruct { val: 3 }.validate().is_ok());
assert!(Data(1).validate().is_err());
assert!(Data(2).validate().is_err());
assert!(Data(3).validate().is_ok());
```
14 changes: 7 additions & 7 deletions docs/src/Attributes/numeric_maximum.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# "maximum" validation
# Numeric: "maximum" validation

The `#[validate(maximum = ???)]` attribute is used to ensure that a value is less than or equal to a given value.

Expand All @@ -7,12 +7,12 @@ The `#[validate(maximum = ???)]` attribute is used to ensure that a value is les
use serde_valid::Validate;

#[derive(Validate)]
struct SampleStruct {
struct Data (
#[validate(maximum = 6)]
val: i32,
}
i32
);

assert!(SampleStruct { val: 5 }.validate().is_ok());
assert!(SampleStruct { val: 6 }.validate().is_ok());
assert!(SampleStruct { val: 7 }.validate().is_err());
assert!(Data(5).validate().is_ok());
assert!(Data(6).validate().is_ok());
assert!(Data(7).validate().is_err());
```
12 changes: 6 additions & 6 deletions docs/src/Attributes/numeric_minimum.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# "minimum" validation
# Numeric: "minimum" validation

The `#[validate(minimum = ???)]` attribute is used to validate that a field is greater than or equal to a given value.

Expand All @@ -7,11 +7,11 @@ The `#[validate(minimum = ???)]` attribute is used to validate that a field is g
use serde_valid::Validate;

#[derive(Validate)]
struct SampleStruct {
struct Data (
#[validate(minimum = 2)]
val: i32,
}
i32,
);

assert!(SampleStruct { val: 1 }.validate().is_err());
assert!(SampleStruct { val: 2 }.validate().is_ok());
assert!(Data(1).validate().is_err());
assert!(Data(2).validate().is_ok());
```
12 changes: 6 additions & 6 deletions docs/src/Attributes/numeric_multiple_of.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# "multiple_of" validation
# Numeric: "multiple_of" validation

The `#[validate(multiple_of = ???)]` attribute is used to validate that a number is a multiple of given number.

Expand All @@ -7,11 +7,11 @@ The `#[validate(multiple_of = ???)]` attribute is used to validate that a number
use serde_valid::Validate;

#[derive(Validate)]
struct TestStruct {
struct Data (
#[validate(multiple_of = 5)]
val: i32,
}
i32,
);

assert!(TestStruct { val: 15 }.validate().is_ok());
assert!(TestStruct { val: 14 }.validate().is_err());
assert!(Data(15).validate().is_ok());
assert!(Data(14).validate().is_err());
```
10 changes: 5 additions & 5 deletions docs/src/Attributes/string_max_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ The `#[validate(max_length = ???)]` attribute is used to validate that a `String
use serde_valid::Validate;

#[derive(Validate)]
struct TestStruct {
struct Data (
#[validate(max_length = 4)]
val: String,
}
String,
);

assert!(TestStruct { val: "test".to_owned() }.validate().is_ok());
assert!(TestStruct { val: "test1".to_owned() }.validate().is_err());
assert!(Data("test".to_owned()).validate().is_ok());
assert!(Data("test1".to_owned()).validate().is_err());
```
10 changes: 5 additions & 5 deletions docs/src/Attributes/string_min_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ The `#[validate(min_length = ???)]` attribute is used to validate that a `String
use serde_valid::Validate;

#[derive(Validate)]
struct TestStruct {
struct Data (
#[validate(min_length = 4)]
val: String,
}
String,
);

assert!(TestStruct { val: "tes".to_owned() }.validate().is_err());
assert!(TestStruct { val: "test".to_owned() }.validate().is_ok());
assert!(Data("tes".to_owned()).validate().is_err());
assert!(Data("test".to_owned()).validate().is_ok());
```
18 changes: 18 additions & 0 deletions docs/src/Attributes/string_pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# String: "pattern" validation

The `#[validate(pattern = ???)]` attribute is used to validate a string against a regular expression.

```rust
# extern crate regex;
# extern crate serde_valid;
use serde_valid::Validate;

#[derive(Validate)]
struct Data (
#[validate(pattern = r"^\d{4}-\d{2}-\d{2}$")]
String,
);

let s = Data("2020-09-10".to_owned());
assert!(s.validate().is_ok());
```
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Attributes](./Attributes/index.md)
- [String: "max_length" validation](./Attributes/string_max_length.md)
- [String: "min_length" validation](./Attributes/string_min_length.md)
- [String: "pattern" validation](./Attributes/string_pattern.md)
- [Numeric: "maximum" validation](./Attributes/numeric_maximum.md)
- [Numeric: "minimum" validation](./Attributes/numeric_minimum.md)
- [Numeric: "exclusive_maximum" validation](./Attributes/numeric_exclusive_maximum.md)
Expand Down

0 comments on commit 4e08245

Please sign in to comment.