std-method
Vec::new
Construct an empty vector. Specify the element type if subsequent operations do not determine it. No element storage is allocated by new itself. Expected stdout (not executed): true ["ready"] Common mistake: Expecting Vec::new() to contain default values.
Formal Syntax & Structure
rust syntaxrust
pub const fn new() -> Vec<T>Working Example
Example Snippetrust
fn main() { let mut labels: Vec<&str> = Vec::new(); println!("{}", labels.is_empty()); labels.push("ready"); println!("{labels:?}");}