I have this function
pub struct Config {
pub query: String,
pub filename: String,
}
impl Config {
pub fn new(args: &Vec<String>) -> Result<Config, &str> {
if args.len() > 3 {
return Err("Error");
}
let query = args[1].clone();
let filename = args[2].clone();
Ok(Config {query, filename})
}
}
pub fn run(config: &Config) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(config.filename)?;
for i in search(&config.query, &contents) {
println!("Found: {}", i);
}
Ok(())
}
I got an error "cannot move out of config.filename
which is behind a shared reference" when run this
if let Err(e) = run(&config) {
println!("Error:{}", e);
process::exit(1);
}
run(&config);
I really don't know why I got this error. Can anyone please explain it? Many thanks.