Normally, there is only one owner for a specific value (except for things like Rc<T>
). Then what is the owner of the value 4
below since the variable myVar
borrows it from something? I want to know what is that something.
let myVar = &4;
Normally, there is only one owner for a specific value (except for things like Rc<T>
). Then what is the owner of the value 4
below since the variable myVar
borrows it from something? I want to know what is that something.
let myVar = &4;
Literals, be they:
4
"Hello, World"
Have a 'static
lifetime as their value is hard-coded into the library or executable itself. For example, on Linux, they would be found either in the .text
segment or the .rodata
segment of the ELF binary.
In that sense, you can think of them as being owned by the program itself.