ownership

Rust Owned values and scope

A scope is a region of code in which a name can be used. An initialized owner normally reaches its drop point when execution leaves its associated drop scope. Scope and visibility are related, but moving a value can end its availability earlier. Expected output (not executed): Draft Finished Why: The inner note is no longer available after the block; its owned String is cleaned up there. Common mistake: Using a name outside its block or assuming all borrows last to the end of that block.

Formal Syntax & Structure

rust syntaxrust
{ let name = value; }

Working Example

Example Snippetrust
fn main() {    {        let note = String::from("Draft");        println!("{note}");    }    println!("Finished");}
Rust Reference