Syntax

Rust Create a Vector Syntax

In Rust, create a vector: creates a growable list — let mut v = vec![1, 2, 3]; v.push(4);

Quick Answer

Syntax
let mut v = vec![1, 2, 3]; v.push(4);
RustSyntax

Create a Vector

Code example
let mut v = vec![1, 2, 3]; v.push(4);

Creates a growable list.

Learn More

How to create a vector in Rust

  1. Open your Rust file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Rust Create a Vector Syntax

Use let mut v = vec![1, 2, 3]; v.push(4);.

Related Syntax References

Frequently asked questions

What is the Rust syntax for create a vector?

Use this pattern: let mut v = vec![1, 2, 3]; v.push(4);

Can I copy this Rust code example?

Yes. Use Copy code and adapt the example to your program.

Is this Rust syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify