From: Ummon Date: Tue, 6 Jan 2015 18:46:00 +0000 (+0100) Subject: Improve the function 'from_elem(..)'. X-Git-Url: http://git.euphorik.ch/?p=crypto_lab1.git;a=commitdiff_plain;h=HEAD;hp=d7f0bb987b21e93a5798403d294f7905151682f7 Improve the function 'from_elem(..)'. --- 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() +}