Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Last active December 16, 2015 18:09
Show Gist options
  • Save JohnMurray/5476038 to your computer and use it in GitHub Desktop.
Save JohnMurray/5476038 to your computer and use it in GitHub Desktop.
Question for Rust IRC
/*
* Question: should this be the correct way to initialize a new vector
* with a set capacity? Seems al little verbose.
*/
fn main() -> () {
let mut a : ~[int] = ~[];
vec::reserve(&mut a, 20);
}
@JohnMurray
Copy link
Author

So to make this complete for anyone else who looks, Jeaye from the Mozilla Rust IRC suggested using vec::with_capacity such that:

fn main() -> () {
  let a : ~[int] = vec::with_capacity(20);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment