rustlings

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

move_semantics5.rs (522B)


      1 #![allow(clippy::ptr_arg)]
      2 
      3 // Borrows instead of taking ownership.
      4 // It is recommended to use `&str` instead of `&String` here. But this is
      5 // enough for now because we didn't handle strings yet.
      6 fn get_char(data: &String) -> char {
      7     data.chars().last().unwrap()
      8 }
      9 
     10 // Takes ownership instead of borrowing.
     11 fn string_uppercase(mut data: String) {
     12     data = data.to_uppercase();
     13 
     14     println!("{data}");
     15 }
     16 
     17 fn main() {
     18     let data = "Rust is great!".to_string();
     19 
     20     get_char(&data);
     21 
     22     string_uppercase(data);
     23 }