11use std:: time:: Duration ;
22
3+ /// Validate that the duration is less than or equal to the maximum.
4+ ///
5+ /// # Example
6+ ///
7+ /// ```rust
8+ /// use std::time::Duration;
9+ ///
10+ /// use serde_valid::utils::duration_maximum;
11+ /// use serde_valid::Validate;
12+ ///
13+ /// #[derive(Validate)]
14+ /// struct TestStruct {
15+ /// #[validate(custom(duration_maximum(Duration::from_micros(5))))]
16+ /// val: Duration,
17+ /// }
18+ ///
19+ /// let s = TestStruct {
20+ /// val: Duration::from_micros(5),
21+ /// };
22+ ///
23+ /// assert!(s.validate().is_ok());
24+ /// ```
325#[ allow( dead_code) ]
426pub fn duration_maximum (
527 maximum : Duration ,
@@ -15,6 +37,28 @@ pub fn duration_maximum(
1537 }
1638}
1739
40+ /// Validate that the duration is greater than or equal to the minimum.
41+ ///
42+ /// # Example
43+ ///
44+ /// ```rust
45+ /// use std::time::Duration;
46+ ///
47+ /// use serde_valid::utils::duration_minimum;
48+ /// use serde_valid::Validate;
49+ ///
50+ /// #[derive(Validate)]
51+ /// struct TestStruct {
52+ /// #[validate(custom(duration_minimum(Duration::from_micros(5))))]
53+ /// val: Duration,
54+ /// }
55+ ///
56+ /// let s = TestStruct {
57+ /// val: Duration::from_secs(5),
58+ /// };
59+ ///
60+ /// assert!(s.validate().is_ok());
61+ /// ```
1862#[ allow( dead_code) ]
1963pub fn duration_minimum (
2064 minimum : Duration ,
@@ -30,6 +74,28 @@ pub fn duration_minimum(
3074 }
3175}
3276
77+ /// Validate that the duration is less than the exclusive maximum.
78+ ///
79+ /// # Example
80+ ///
81+ /// ```rust
82+ /// use std::time::Duration;
83+ ///
84+ /// use serde_valid::utils::duration_exclusive_maximum;
85+ /// use serde_valid::Validate;
86+ ///
87+ /// #[derive(Validate)]
88+ /// struct TestStruct {
89+ /// #[validate(custom(duration_exclusive_maximum(Duration::from_micros(5))))]
90+ /// val: Duration,
91+ /// }
92+ ///
93+ /// let s = TestStruct {
94+ /// val: Duration::from_micros(4),
95+ /// };
96+ ///
97+ /// assert!(s.validate().is_ok());
98+ /// ```
3399#[ allow( dead_code) ]
34100pub fn duration_exclusive_maximum (
35101 maximum : Duration ,
@@ -45,6 +111,28 @@ pub fn duration_exclusive_maximum(
45111 }
46112}
47113
114+ /// Validate that the duration is greater than the exclusive minimum.
115+ ///
116+ /// # Example
117+ ///
118+ /// ```rust
119+ /// use std::time::Duration;
120+ ///
121+ /// use serde_valid::utils::duration_exclusive_minimum;
122+ /// use serde_valid::Validate;
123+ ///
124+ /// #[derive(Validate)]
125+ /// struct TestStruct {
126+ /// #[validate(custom(duration_exclusive_minimum(Duration::from_micros(5))))]
127+ /// val: Duration,
128+ /// }
129+ ///
130+ /// let s = TestStruct {
131+ /// val: Duration::from_micros(6),
132+ /// };
133+ ///
134+ /// assert!(s.validate().is_ok());
135+ /// ```
48136#[ allow( dead_code) ]
49137pub fn duration_exclusive_minimum (
50138 minimum : Duration ,
0 commit comments