Syntax

Rust Declare a Variable Syntax

In Rust, declare a variable: variables are immutable by default — let x = 5; let mut y = 1;

Quick Answer

Syntax
let x = 5; let mut y = 1;
RustSyntax

Declare a Variable

Code example
let x = 5; let mut y = 1;

Variables are immutable by default.

Learn More

How to declare a variable in Rust

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

Rust Declare a Variable Syntax

Use let x = 5; let mut y = 1;.

Related Syntax References

Frequently asked questions

What is the Rust syntax for declare a variable?

Use this pattern: let x = 5; let mut y = 1;

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