It looks like your program has a few errors, so let's try to step through them one by one.
First is this one on line 75:
error[E0382]: use of moved value: `location_loc1`
--> src/main.rs:75:40
|
37 | async fn print_events(mut selector_loc1:i8, location_loc1: PathBuf) {
| ------------- move occurs because `location_loc1` has type `std::path::PathBuf`, which does not implement the `Copy` trait
...
75 | let test = location_loc1;
| ^^^^^^^^^^^^^ value used here after move
...
89 | printtype(location_loc1,selector_loc1);
| ------------- value moved here, in previous iteration of loop
We can reduce it down to this:
use std::path::PathBuf;
fn foo(location_loc1: PathBuf) {
let test = location_loc1;
println!("{}", location_loc1.display());
}
(playground)
The reason this fails is because you've moved the location_loc1
value into test
on line 75 of your code, then try to use it again later on. But when you move the location_loc1
value to another location the original variable is no longer initialized, so trying to use it later on doesn't make sense.
The second error is almost identical to the first:
error[E0382]: borrow of moved value: `location_loc1`
--> src/main.rs:76:42
|
37 | async fn print_events(mut selector_loc1:i8, location_loc1: PathBuf) {
| ------------- move occurs because `location_loc1` has type `std::path::PathBuf`, which does not implement the `Copy` trait
...
75 | let test = location_loc1;
| ------------- value moved here
76 | let parent = location_loc1.parent().map(|p| p.to_owned()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^ value borrowed here after move
We can use the same reasoning here. The variable in location_loc1
has been moved into test
so the location_loc1
variable no longer contains anything and trying to use it doesn't make sense.
The "which does not implement the Copy
trait" bit is because the only time you can continue using a value after it has been assigned somewhere else is when the type implements Copy
. The Copy
trait is special and tells the compiler that assignment should copy the value's bytes to the new variable and leave the original variable intact.
I'm not sure what you are trying to accomplish here so can't provide the right fix, although you might be able to explicitly make a copy of the path instead of moving it (i.e. let test = location_loc1.clone()
).
You also get this error message:
error[E0596]: cannot borrow `location_loc1` as mutable, as it is not declared as mutable
--> src/main.rs:77:29
|
37 | async fn print_events(mut selector_loc1:i8, location_loc1: PathBuf) {
| ------------- help: consider changing this to be mutable: `mut location_loc1`
...
77 | location_loc1.push(parent);
| ^^^^^^^^^^^^^ cannot borrow as mutable
That's because the push()
method takes &mut self
because it is mutating the PathBuf
. However you haven't said we are allowed to mutate location_loc1
(by marking it as mut
), so calling a method which borrows self
as mut
isn't allowed.
The compiler even tells you how you can fix the problem: "help: consider changing this to be mutable: mut location_loc1
".
Your Down Votes on Stack Exchange
I think what is happening is that you haven't given the right amount of context for people to adequately answer your question.
For example, those two lines alone don't really give me enough information to reproduce your issue, although I could make a pretty good guess based on my experience with similar "copy not implemented" errors. What I mean is that if I copied that into an empty file (or even the body of a main()
function) and pointed the compiler at it I would either get a syntax error or the compiler would complain that location_loc1
doesn't exist and I don't know what type it is meant to have.
Similarly, I'm missing crucial information like which precise statement was triggering the error and hints for resolving the issue that the compiler is providing.
People aren't trying to be patronising or difficult here, without a Minimal, Reproducible example it really is hard to help you figure out what caused your problem.
On the other end of the spectrum, giving someone a link to a full repository is too much context. I now need to clone your repository and sift through a 203-line main.rs
file in order to figure out what is going wrong. Considering most people are answering questions on the internet in their own time because they want to be nice, you don't want to take advantage of that good will by making them waste half an hour reading your entire program (in reality, most people won't bother and will just leave your question unanswered).
As an aside, I know it's frustrating when people keep proposing solutions which don't work for your situation but try not to be too vocal about other platforms. It's not a good look.