Syntax

Rust Declare a Constant Syntax

In Rust, declare a constant: declares a typed constant — const MAX: u32 = 100;

Quick Answer

Syntax
const MAX: u32 = 100;
RustSyntax

Declare a Constant

Code example
const MAX: u32 = 100;

Declares a typed constant.

Learn More

How to declare a constant 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 Constant Syntax

Use const MAX: u32 = 100;.

Related Syntax References

Frequently asked questions

What is the Rust syntax for declare a constant?

Use this pattern: const MAX: u32 = 100;

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