rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

primitive_types2.rs (958B)


      1 // Characters (`char`)
      2 
      3 fn main() {
      4     // Note the _single_ quotes, these are different from the double quotes
      5     // you've been seeing around.
      6     let my_first_initial = 'C';
      7     if my_first_initial.is_alphabetic() {
      8         println!("Alphabetical!");
      9     } else if my_first_initial.is_numeric() {
     10         println!("Numerical!");
     11     } else {
     12         println!("Neither alphabetic nor numeric!");
     13     }
     14 
     15     // TODO: Analogous to the example before, declare a variable called `your_character`
     16     // below with your favorite character.
     17     // Try a letter, try a digit (in single quotes), try a special character, try a character
     18     // from a different language than your own, try an emoji 😉
     19 
     20     let your_character = '😉';
     21 
     22     if your_character.is_alphabetic() {
     23         println!("Alphabetical!");
     24     } else if your_character.is_numeric() {
     25         println!("Numerical!");
     26     } else {
     27         println!("Neither alphabetic nor numeric!");
     28     }
     29 }