Repository navigation
Commit 3641daf
authored
Rollup merge of #163138 - sorairolake:feature/more-duration-constants, r=clarfonthey
feat(time): add `Duration::{WEEK, DAY, HOUR, MINUTE}`
- Tracking issue: #57391
This pull request adds associated constants for representing one week, one day, one hour, or one minute to `Duration`.
In the same way as #162195 and #162199, the exact number of seconds corresponding to one week, one day, one hour, and one minute are clearly specified in the documentation. Documentation tests are used to verify the correctness of these descriptions.
I initially proposed this as an ACP. However, the `duration_constants` feature is still unstable, and the ACP simply adds associated constants for units larger than the second to the feature, I determined that it could be incorporated into the feature.
By making `Duration::WEEK` and `Duration::DAY` dependent on the `duration_constructors` feature, these associated constants can be removed if `Duration::from_weeks` and `Duration::from_days` are not stabilized. Therefore, even if the `duration_constructors` feature is not stabilized, the `duration_constants` feature can be stabilized.
```rust
impl Duration {
pub const WEEK: Duration = Duration::from_weeks(1);
pub const DAY: Duration = Duration::from_days(1);
pub const HOUR: Duration = Duration::from_hours(1);
pub const MINUTE: Duration = Duration::from_mins(1);
}
```
- See also: rust-lang/libs-team#8691 file changed
Lines changed: 80 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
139 | 219 | | |
140 | 220 | | |
141 | 221 | | |
| |||
0 commit comments