You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-04 05:40:29 +02:00
Split off function call to make pattern match clearer (#2785)
I think doing the call to `Duration::try_from_secs_f32` in the pattern match is a bit verbose since the function name is so long. I usually split this off into a separate variable so that it's easier to see the pattern match syntax.
This commit is contained in:
@ -8,7 +8,9 @@ lets you execute different code depending on whether a value matches a pattern:
|
||||
use std::time::Duration;
|
||||
|
||||
fn sleep_for(secs: f32) {
|
||||
if let Ok(duration) = Duration::try_from_secs_f32(secs) {
|
||||
let result = Duration::try_from_secs_f32(secs);
|
||||
|
||||
if let Ok(duration) = result {
|
||||
std::thread::sleep(duration);
|
||||
println!("slept for {duration:?}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user