RRust By Example
beginnerBasics

Constants and Static

Difference between const and static variables in Rust.

Constants and Static

Difference between const and static variables in Rust.

Difficulty

Beginner

Code

rust
const MAX_POINTS: u32 = 100_000;
static LANGUAGE: &str = "Rust";

fn main() {
    println!("Max points: {}", MAX_POINTS);
    println!("Language: {}", LANGUAGE);
}

Explanation

This example demonstrates how to use constants and static in Rust. Read the code carefully to understand the flow. Pay attention to where values are created, borrowed, moved, or consumed.

Key Concepts

  • Rust's strong type system catches errors at compile time
  • Ownership and borrowing rules ensure memory safety
  • Pattern matching makes code expressive and exhaustive

Related Topics

Browse more examples in the basics category to build a complete understanding of this topic.

More Basics Examples