In this lesson, you will learn how to distinguish between pointers that manage a resource's lifecycle and those that merely provide temporary access to it.
The Nature of Ownership
In Rust, "owning" a pointer means that the pointer is responsible for the resource it points to—most notably, it is responsible for deallocating that memory when it goes out of scope. When you use Box<T>, you are using an owning pointer. If you pass a Box<T> to a function, the function becomes the new owner, and the original scope can no longer access that data. It is a transfer of responsibility.
Borrowing as a Guest Pass
Conversely, a "borrowing" pointer—a reference like &T or &mut T—acts as a temporary guest pass. It provides access to the data, but it carries no responsibility for the underlying memory. The lifetime of a borrow is strictly constrained by the lifetime of the owner. You cannot "move" out of a borrow because you don't own the data; you are merely looking at it.
Consider the distinction here:
fn consume(item: Box<i32>) {
println!("I own this: {}", item);
} // item is dropped here
fn inspect(item: &i32) {
println!("I am just looking at: {}", item);
} // No drop occurs; I am just a guest
fn main() {
let data = Box::new(42);
inspect(&data); // Borrowing: data remains valid here
consume(data); // Owning: data is moved and destroyed
// inspect(&data); // ERROR: data was moved
}
Why the Distinction Matters
The core of Rust’s safety model is preventing "use-after-free" bugs. Owning pointers ensure that there is exactly one chain of responsibility for cleanup. Borrowing pointers ensure that multiple parts of your code can look at the data simultaneously without the risk of the data disappearing mid-access. When you see a function signature, asking "Does this take an owning type or a reference?" tells you immediately whether you are handing over control of your object’s lifetime or simply offering a temporary window into its state.
Key Takeaway: Owning pointers transfer the responsibility of destruction, while borrowing pointers provide temporary, read-only or read-write access without affecting the object's lifespan.