I am trying to learn the ins and outs of memory in Rust. When a vector is created inside a function and then returned, is a reference returned or is the entire vector copied?
Example:
use std::io;
fn line_to_ints() -> Vec<u32> {
let mut line = String::new();
io::stdin()
.read_line(&mut line)
.expect("Failed to read line");
return line
.split(" ")
.map(|x| x.parse().expect("Not an integer!"))
.collect();
}
Will the return behavior here also be the same for all other non-primitive data types?
Unlike Is there any way to return a reference to a variable created in a function?, I would like to know a bit more about what is happening under the hood. The answers to that question do not provide clarity as to whether or not the vector is created and then copied to a new location, or ownership of the pointer is returned I understand vectors are created on the heap so I imagine a pointer is involved.