Advertisement
cwchen

[Rust] custom from_slice constructor of Vector class.

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