expression

Rust Places versus values

A place denotes a storage location, such as a variable or an array element. A value computation supplies a result. Reading a place can copy or move its contents depending on the context and type. Expected output (not executed): [10, 8] Why: The left index selects a destination; the right side computes a new integer. Common mistake: Not every expression is an assignment destination: `stock[0] + 1 = 7` is invalid.

Formal Syntax & Structure

rust syntaxrust
place = value_expression;

Working Example

Example Snippetrust
fn main() {    let mut stock = [4, 8];    stock[0] = stock[1] + 2;    println!("{stock:?}");}
Rust Reference