Move Semantics: Function Return

Overview

Returning a value transfers ownership to the caller. Function boundaries follow the same move rules as assignment.

This means ownership can flow out of one scope and into another through return values, controlling exactly where data remains valid.

Official Rust Book: Return Values and Scope


Code example