fn stringify_name_with_title(name: &Vec<String>) -> String {
name.push(String::from("Esq."));`{}`
let full = name.join(" ");
full
}
fn main() {
let name = vec![String::from("Ferris")];
let first = &name[0];
stringify_name_with_title(&name);
println!("{}", first);
}
The first suggested fix mutates the name rending the access of first in main problematic.
fn stringify_name_with_title(name: &mut Vec<String>) -> String {
name.push(String::from("Esq."));
let full = name.join(" ");
full
}
The second solution moves the name causing the same problem.
fn stringify_name_with_title(mut name: Vec<String>) -> String {
name.push(String::from("Esq."));
let full = name.join(" ");
full
}
main
branch to see if this has already been fixed, in this file:I am completely new to Rust and started going through the book just 2-3 days ago. Sorry if I have incorrectly pointed out anything here.
URL to the section(s) of the book with this problem: https://rust-book.cs.brown.edu/ch04-03-fixing-ownership-errors.html#fixing-an-unsafe-program-copying-vs-moving-out-of-a-collection
Description of the problem: The diagram tells us that
v
has lostRead
access, which in reality it should not.Suggested fix: Mark
v
withR
Apart from this, I think the section Fixing an Unsafe Program: Not Enough Permissions does not take into account the previously linked
main
function for the suggested solutions.Here is the described
main
function.The first suggested fix mutates the
name
rending the access offirst
inmain
problematic.The second solution moves the
name
causing the same problem.