mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
4 years ago
|
use std::thread;
|
||
|
use std::time::Duration;
|
||
|
|
||
|
fn simulated_expensive_calculation(intensity: u32) -> u32 {
|
||
|
println!("calculating slowly...");
|
||
|
thread::sleep(Duration::from_secs(2));
|
||
|
intensity
|
||
|
}
|
||
|
|
||
|
// ANCHOR: here
|
||
|
fn generate_workout(intensity: u32, random_number: u32) {
|
||
|
if intensity < 25 {
|
||
|
println!(
|
||
|
"Today, do {} pushups!",
|
||
|
simulated_expensive_calculation(intensity)
|
||
|
);
|
||
|
println!(
|
||
|
"Next, do {} situps!",
|
||
|
simulated_expensive_calculation(intensity)
|
||
|
);
|
||
|
} else {
|
||
|
if random_number == 3 {
|
||
|
println!("Take a break today! Remember to stay hydrated!");
|
||
|
} else {
|
||
|
println!(
|
||
|
"Today, run for {} minutes!",
|
||
|
simulated_expensive_calculation(intensity)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// ANCHOR_END: here
|
||
|
|
||
|
fn main() {
|
||
|
let simulated_user_specified_value = 10;
|
||
|
let simulated_random_number = 7;
|
||
|
|
||
|
generate_workout(simulated_user_specified_value, simulated_random_number);
|
||
|
}
|