Skip to content

Instantly share code, notes, and snippets.

@denisoster
Created March 28, 2020 14:34
Show Gist options
  • Save denisoster/6bbe430ae2f4f9a1bd794653e340944b to your computer and use it in GitHub Desktop.
Save denisoster/6bbe430ae2f4f9a1bd794653e340944b to your computer and use it in GitHub Desktop.
/Users/denisoster/.cargo/bin/cargo run --color=always --package iwt --bin iwt
Compiling iwt v0.1.0 (/Users/denisoster/Projects/rust/iwt)
error[E0382]: borrow of moved value: `line`
--> src/main.rs:18:41
|
14 | let line = line.unwrap(); // Ignore errors.
| ---- move occurs because `line` has type `std::string::String`, which does not implement the `Copy` trait
...
18 | fs::copy(line, format!("to/{}", line));
| ---- value moved here ^^^^ value borrowed here after move
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`.
error: could not compile `iwt`.
To learn more, run the command again with --verbose.
Process finished with exit code 101
use std::fs::File;
use std::io::{BufReader, BufRead};
use std::fs;
fn main() {
let filename = ".copy-files";
// Open the file in read-only mode (ignoring errors).
let file = File::open(filename).unwrap();
let reader = BufReader::new(file);
// Read the file line by line using the lines() iterator from std::io::BufRead.
for (index, line) in reader.lines().enumerate() {
let line = line.unwrap(); // Ignore errors.
// Show the line and its number.
println!("{}: {}", index, line);
fs::copy(line, format!("to/{}", line));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment