projects
/
crypto_lab1.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d7f0bb9
)
Improve the function 'from_elem(..)'.
master
author
Ummon
<greg.burri@gmail.com>
Tue, 6 Jan 2015 18:46:00 +0000
(19:46 +0100)
committer
Ummon
<greg.burri@gmail.com>
Tue, 6 Jan 2015 18:46:00 +0000
(19:46 +0100)
lab1_rust/src/utils.rs
patch
|
blob
|
history
diff --git
a/lab1_rust/src/utils.rs
b/lab1_rust/src/utils.rs
index
b6be23a
..
c86df3b
100644
(file)
--- a/
lab1_rust/src/utils.rs
+++ b/
lab1_rust/src/utils.rs
@@
-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()
+}