borrowing

Rust Shared access: read without consuming

Use a shared reference when a caller needs to inspect data while the original owner retains it. Multiple readers can use the same ordinary value. Direct mutation through that reference is forbidden; interior mutability is a separate, controlled mechanism. Expected output (not executed): Paid / Paid Owner: Paid Why: Both readers refer to the same String, and neither takes it away from receipt. Common mistake: Assuming every reference is an independently owned copy of its target.

Formal Syntax & Structure

rust syntaxrust
let view = &owner;

Working Example

Example Snippetrust
fn main() {    let receipt = String::from("Paid");    let clerk = &receipt;    let customer = &receipt;    println!("{clerk} / {customer}");    println!("Owner: {receipt}");}
Rust Reference