Owned Strings

We'll cover the following...

There’s a big restriction on program memory versus stack; once the compiler creates your executable, the program memory is frozen. When your executable is running, it cannot change data in program memory or add new things there.

Let’s give a simple program we’d like to make work somehow. I’d like to create a new string that combines my first and last name together. Naively, I would try to write something like this:

Press + to interact
fn main() {
let first_name = "Michael";
let last_name = " Snoyman";
let full_name = first_name + last_name;
println!("Full name is {}", full_name);
}

This program doesn’t work. We’ll look at the compiler error in a bit to get help fixing it. But first, let me ask you a basic question, where should the full_name value live in memory? We know it can’t live in program memory, since this string is going to be created while the ...