update duration solution

This commit is contained in:
AF 2026-04-09 12:56:16 +00:00
parent 7758866025
commit b39bfa57cf
Signed by: alisa
SSH Key Fingerprint: SHA256:vNY4pdIZvO1FYJKHROkdHLtvyopizvZVAEwg9AF6h04

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