rustlings

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

move_semantics5.rs (485B)


      1 #![allow(clippy::ptr_arg)]
      2 
      3 // TODO: Fix the compiler errors without changing anything except adding or
      4 // removing references (the character `&`).
      5 
      6 // Shouldn't take ownership
      7 fn get_char(data: &String) -> char {
      8     data.chars().last().unwrap()
      9 }
     10 
     11 // Should take ownership
     12 fn string_uppercase(mut data: String) {
     13     data = data.to_uppercase();
     14 
     15     println!("{data}");
     16 }
     17 
     18 fn main() {
     19     let data = "Rust is great!".to_string();
     20 
     21     get_char(&data);
     22 
     23     string_uppercase(data);
     24 }