Rust Fundamentals · 15 XP Pro
Booleans and chars
A bool is either true or false. Combine booleans with && (and), ||
(or) and ! (not). Comparisons like ==, < and >= produce a bool. The
operators && and || short-circuit: the right side runs only if needed.
let year = 2024;
let divisible_by_four = year % 4 == 0;
let not_century = year % 100 != 0;
println!("{}", divisible_by_four && not_century); // true
A char is a single Unicode character in single quotes: 'a', '7',
'ß', '🦀'. It takes 4 bytes, and is not the same as a one-letter string
("a"). Useful methods:
c.is_alphabetic(),c.is_numeric()andc.is_whitespace()returnbool.c.to_ascii_uppercase()andc.to_ascii_lowercase()return a newcharand leave non-letters untouched.
let c = 'q';
let big = if c.is_alphabetic() { c.to_ascii_uppercase() } else { c };
// big is 'Q'
Your task
Write these public functions:
is_leap_year(year: u32) -> bool: a leap year is divisible by 4, except years divisible by 100, unless they are also divisible by 400. So 2000 and 2024 are leap years; 1900 and 2023 are not.capitalize_letter(c: char) -> char: uppercase the character if it is a letter, otherwise return it unchanged.is_vowel(c: char) -> bool: true fora e i o uin either case.