From 649887a9804c4658399b281b1b4c7f0f9fdd6f73 Mon Sep 17 00:00:00 2001 From: Ummon Date: Tue, 6 Jan 2015 19:46:00 +0100 Subject: [PATCH] Improve the function 'from_elem(..)'. --- lab1_rust/src/utils.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lab1_rust/src/utils.rs b/lab1_rust/src/utils.rs index b6be23a..c86df3b 100644 --- a/lab1_rust/src/utils.rs +++ b/lab1_rust/src/utils.rs @@ -1,8 +1,5 @@ +use std::iter; -pub fn from_elem(nb_elem: uint, t: T) -> Vec { - 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(nb_elem: uint, t: T) -> Vec { + iter::repeat(t).take(nb_elem).collect() +} -- 2.45.2