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