Copy Values

We'll cover the following...

OK, I get it. A value has an owner, and you can’t use a value after it’s been moved to a new owner. Awesome. Then why does this code work?

Press + to interact
fn count(apples: i32) {
println!("You have {} apples", apples);
}
fn price(apples: i32) -> i32 {
apples * 8
}
fn main() {
let apples: i32 = 10;
count(apples);
let price = price(apples);
println!("The apples are worth {} cents", price);
}

We create the value 10, owned by the main function, and put it in the ...

Access this course and 1400+ top-rated courses and projects.