Added helper to create Vec with a given size

This commit is contained in:
Paul Masurel
2017-03-29 11:26:18 +09:00
parent 456dd3a60d
commit f0dc0de4b7
3 changed files with 11 additions and 7 deletions

View File

@@ -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
}