flâneur — a map of the web's best reading

What is Ownership? - The Rust Programming Language

rust-book.cs.brown.edu · 2,997 words · saved by 1 readers

Ownership is a discipline for ensuring the safety of Rust programs. To understand ownership, we first need to understand what makes a Rust program safe (or unsafe). Let’s start with an example. This program is safe to execute: We can make this program unsafe to execute by moving the call to read before the definition of x: Note: in this chapter, we will use many code examples that do not compile. Make sure to look for the question mark crab if you are not sure whether a program should compile or not. This second program is unsafe because read(x) expects x to have a value of type bool, but x doesn’t have a value yet. When a program like this is executed by an interpreter, then reading x before it’s defined would raise an exception such as Python’s NameError or Javascript’s ReferenceError. But exceptions come at a cost. Each time an interpreted program reads a variable, then the interpreter must check whether that variable is defined. Rust’s goal is to compile programs into efficient bin

What is Ownership? - The Rust Programming Language Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Auto Light Rust Coal Navy Ayu The Rust Programming Language What Is Ownership? Ownership is a discipline for ensuring the safety of Rust programs. To understand ownership, we first need to understand what makes a Rust program safe (or unsafe). Safety is the Absence of Undefined Behavior Let’s start with an example. This program is safe to execute: fn read(y: bool) { if y { println!("y is true!");

Explore this link on the map →

related reading