Complete the code to declare a character variable with the letter 'a'.
let letter: char = '[1]';
In Rust, a character is declared using single quotes around a single character, like 'a'.
Complete the code to print the Unicode code point of the character 'Z'.
let ch: char = 'Z'; println!("{}", ch [1] u32);
to_digit without an argument.To get the Unicode code point of a character like 'Z', cast it to u32 using as u32.
Fix the error in the code to check if a character is a digit.
let c = '5'; if c.[1]() { println!("It's a digit!"); }
is_digit() without arguments (it requires a radix).is_alphabetic() which checks for letters.The correct method to check if a character is a digit is is_numeric() in Rust.
Fill both blanks to create a map from characters to their uppercase versions for letters only.
let letters = ['a', 'b', 'c', '1']; let uppercase_map: std::collections::HashMap<char, char> = letters.iter() .filter(|&&c| c.[1]()) .map(|&c| (c, c.[2]())) .collect();
to_lowercase() instead of uppercase.Use is_alphabetic() to filter letters, and to_ascii_uppercase() to convert them to uppercase.
Fill all three blanks to create a dictionary comprehension that maps characters to their Unicode code points if they are digits.
let chars = ['a', '3', '7', 'b']; let digit_map: std::collections::HashMap<char, u32> = chars.iter() .filter(|&&c| c.[1]()) .map(|&c| (c, c [2] [3])) .collect();
is_alphabetic() instead of is_numeric().u32.Filter digits with is_numeric(), cast characters to u32 using as to get Unicode code points.