I am trying to format two &str values (one literal one is a value of a vector).
When I format it though it returns a string, so I try to turn it back into a &str so I can use it for the mdata vector
Here's the code:
fn part2(data: Vec<&str>) {
let mut mdata = data.clone();
for i in 0..data.len() {
let currentline = &mdata[i];
let parts = currentline.split(" ").collect::<Vec<_>>();
if parts[0] != "acc" {
if parts[0] == "nop" {
let somestr = format!("jmp {:?}",parts[1]).to_owned();
let hopestr = somestr.as_str();
mdata[i] = hopestr;
} else {
let some_string = format!("jmp {}",parts[1]);
let some_str = some_string.as_str();
mdata[i] = some_str;
}
let mut taken: Vec<i32> = Vec::new();
part1(mdata.clone(),&mut taken,0i32,&mut 0i32,true);
} else {
continue;
}
}
}
This is the error.
I have absolutely no idea what to do with it. I tried to reproduce the error here:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e2cee34d88ef4320f7fc43b1fd35304c
But this worked without errors. I ran the same thing locally and it worked without errors too. I have no idea what is going on, please tell me a solution and how the solution works.
As a little context I'm trying to make code to parse a file and solve part 2 of this problem:
https://adventofcode.com/2020/day/8
I have looked at many similar issues but I couldn't find a solution.
Thank you in advance.