This commit is contained in:
parent
cbcee48b40
commit
a64e7c341e
@ -4,12 +4,12 @@ Define `FIVE_SECONDS` as `const`:
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
# use std::time::Duration;
|
# use std::time::Duration;
|
||||||
# const fn unwrap_time(d: Option<Duration>) -> Duration { match d { Some(d) => d, None => panic!() } }
|
# const fn unwrap<T: Copy>(o: Option<T>) -> T { match o { Some(t) => t, None => panic!() } }
|
||||||
const TWO_SECONDS: Duration = Duration::from_secs(2);
|
const TWO_SECONDS: Duration = Duration::from_secs(2);
|
||||||
# /*
|
# /*
|
||||||
const FIVE_SECONDS: Duration = TWO_SECONDS + Duration::from_secs(3);
|
const FIVE_SECONDS: Duration = TWO_SECONDS + Duration::from_secs(3);
|
||||||
# */
|
# */
|
||||||
# const FIVE_SECONDS: Duration = unwrap_time(TWO_SECONDS.checked_add(Duration::from_secs(3)));
|
# const FIVE_SECONDS: Duration = unwrap(TWO_SECONDS.checked_add(Duration::from_secs(3)));
|
||||||
assert_eq!(FIVE_SECONDS, Duration::from_secs(5));
|
assert_eq!(FIVE_SECONDS, Duration::from_secs(5));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user