Skip to content
masterclass Buddy

Rust · Macro

vec!

The vec! macro creates a Vec from listed elements or by repeating one element. The repeat form uses Clone, and its count can be non-constant.

Last updated

Since
1.0.0

Syntax

macro_rules! vec { () => { ... }; ($elem:expr; $n:expr) => { ... }; ($($x:expr),+ $(,)?) => { ... }; }

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • Vec
  • Clone
  • Rc

Source: vec in std - Rust. Checked 2026-11-03.