Advertisement
cwchen

[Rust] Implementing Clone trait for Vector class.

Sep 14th, 2017
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.37 KB | None | 0 0
  1. // Currently, Copy trait cannot be implemented
  2. // impl<T> Copy for Vector<T> {}
  3.  
  4. impl<T> Clone for Vector<T> where T: Copy + fmt::Display + num::Num {
  5.      fn clone(&self) -> Vector<T> {
  6.          let mut vec: Vec<T> = Vec::new();
  7.  
  8.          for i in 0..(self.vec.len()) {
  9.              vec.push(self.vec[i]);
  10.          }
  11.  
  12.          Vector::<T>{ vec: vec }
  13.      }
  14.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement