rustlings

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

move_semantics2.rs (533B)


      1 fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
      2     let mut vec = vec;
      3 
      4     vec.push(88);
      5 
      6     vec
      7 }
      8 
      9 fn main() {
     10     // You can optionally experiment here.
     11 }
     12 
     13 #[cfg(test)]
     14 mod tests {
     15     use super::*;
     16 
     17     // TODO: Make both vectors `vec0` and `vec1` accessible at the same time to
     18     // fix the compiler error in the test.
     19     #[test]
     20     fn move_semantics2() {
     21         let vec0 = vec![22, 44, 66];
     22 
     23         let vec1 = fill_vec(vec0.clone());
     24 
     25         assert_eq!(vec0, [22, 44, 66]);
     26         assert_eq!(vec1, [22, 44, 66, 88]);
     27     }
     28 }