diff options
author | Paul Masurel <paul.masurel@gmail.com> | 2017-03-29 11:26:18 +0900 |
---|---|---|
committer | Paul Masurel <paul.masurel@gmail.com> | 2017-03-29 11:26:24 +0900 |
commit | f0dc0de4b79d2d99db4f59bf2be1c6267b25e7e5 (patch) | |
tree | 097b322f77611ab3085b11fbccfc4cdb8b92c4b0 /src/common/mod.rs | |
parent | 456dd3a60da67d24afe774312a64a77a3b616c98 (diff) |
Added helper to create Vec with a given size
Diffstat (limited to 'src/common/mod.rs')
-rw-r--r-- | src/common/mod.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/mod.rs b/src/common/mod.rs index 0ab876a..d2d41ce 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -30,3 +30,10 @@ pub trait HasLen { } +pub fn create_vec_with_len<T>(capacity: usize) -> Vec<T> { + let mut v = Vec::with_capacity(capacity); + unsafe { + v.set_len(capacity); + } + v +}
\ No newline at end of file |