Rust Fundamentals · 10 XP
Constants and shadowing
A constant is a value fixed at compile time. Declare it with const, give
it an explicit type, and name it in SCREAMING_SNAKE_CASE. Unlike let,
constants can live outside functions and can never be mut.
const MAX_PLAYERS: u32 = 4;
Shadowing means declaring a new variable with the same name using let.
The old one is hidden from then on. This differs from mut: you create a brand
new variable, so it may even have a different type.
let input = " 42 ";
let input = input.trim(); // still text, but trimmed
let input = input.len(); // now a number
trim() removes whitespace at both ends of a piece of text, and len() gives
its length in bytes.
Your task
- Set the two constants:
SECONDS_PER_MINUTEis60, andSECONDS_PER_HOURmust be computed from it (60 minutes' worth of seconds). - Finish
total_seconds(hours: u32, minutes: u32) -> u32using the constants. - Finish
trimmed_len(text: &str) -> usize. Shadowtextfirst with the trimmed text, then shadow it again with its length, and return that.