5/5
# Ownership ## Example Execute the following command to run [`./solutions/examples/ownership.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/ownership/solutions/examples/ownership.rs) ```shell cargo run --example ownership ``` ## Exercises Exercises are in [`./exercises/src/lib.rs`](https://github.com/Cyfrin/rust-crash-course/blob/main/topics/ownership/exercises/src/lib.rs) ### Exercise 1 ```rust pub fn exercise_1() { let s = "rust".to_string(); let s1 = s; let s2 = s; println!("{s1}"); } ``` Comment out a single line to fix the code. ### Exercise 2 ```rust pub fn exercise_2() { let s = "rust".to_string(); { let s1 = s; println!("{s1}"); } println!("{s}"); } ``` Comment out a single line to fix the code. ### Exercise 3 ```rust pub fn exercise_3() { let s = "rust".to_string(); take(s); println!("{s}"); println!("{s}"); } ``` Comment out a single line to fix the code. ## Test ```shell cargo test ```
Execute the following command to run ./solutions/examples/ownership.rs
Exercises are in ./exercises/src/lib.rs
Comment out a single line to fix the code.
Comment out a single line to fix the code.
Comment out a single line to fix the code.
A hands-on introduction to Ownership - Explore Rust's memory management by learning about variable ownership, moves, and scope. You'll debug code by commenting out lines that cause ownership errors after values are moved.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on August 15, 2025
Rust Developer
Rust Programming BasicsDuration: 6min
Duration: 18min
Duration: 47min
Duration: 15min
Duration: 19min
Duration: 8min
Duration: 12min
Duration: 46min
Duration: 14min
Course Overview
About the course
Introduction to the Rust programming language
Rust variables and functions
Scalar types, arrays, strings, enum, structs, vectors, and hash maps in Rust
Rust control flows: If / else, if let and let else, loop, match
Rust ownership, including borrow and references
Rust error handling
Rust Modules
Rust Traits
Last updated on August 15, 2025