How to Use Compile-Time Computation (const fn) in Rust

Define a function with the `const fn` keyword to allow the compiler to evaluate it at compile time for constant expressions.

Use the const keyword before fn to define a function that the compiler can evaluate at compile time.

const fn square(x: i32) -> i32 {
    x * x
}

const ANSWER: i32 = square(6);

This requires the function body to contain only operations allowed in constant contexts, such as basic arithmetic and recursion, excluding dynamic allocations or trait calls.