update duration solution
All checks were successful
buildbot/mdbook test Build done.

This commit is contained in:
AF 2024-02-16 22:57:04 +00:00
parent cbcee48b40
commit a64e7c341e

View File

@ -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));
``` ```