std-module

std::vec — growable contiguous storage

This module contains Vec and vector-specific iterator types. Vec stores elements in a contiguous sequence; pushing at the end has amortized constant cost, meaning the cost averaged across a sequence of pushes is constant per push. A growth operation may allocate and move existing elements. Expected stdout (not executed): [7, 9, 10] Common mistake: Assuming every push has the same cost or that Vec is a fixed-length array.

Formal Syntax & Structure

rust syntaxrust
use std::vec::Vec;

Working Example

Example Snippetrust
fn main() {    let mut scores = Vec::from([7, 9]);    scores.push(10);    println!("{scores:?}");}
Rust Reference