Improve the function 'from_elem(..)'.
[crypto_lab1.git] / lab1_rust / src / utils.rs
index b6be23a..c86df3b 100644 (file)
@@ -1,8 +1,5 @@
+use std::iter;
 
-pub fn from_elem<T : Copy>(nb_elem: uint, t: T) -> Vec<T> {
-   let mut v = Vec::with_capacity(nb_elem);
-   for _ in range(0u, nb_elem) {
-      v.push(t);
-   }
-   v
-}
\ No newline at end of file
+pub fn from_elem<T : Clone>(nb_elem: uint, t: T) -> Vec<T> {
+   iter::repeat(t).take(nb_elem).collect()
+}