Hello,
I have a Hashmap which I am trying to update inside the for loop, based on if else
statement.
fn makemethdb(file: &String) {
let bed = File::open(file).expect("Can not!");
let bedbuf = BufReader::new(bed);
let mut methmap: HashMap<String, String> = HashMap::new();
let mut chr: String = String::new();
for line in bedbuf.lines(){
let line = line.unwrap();
let linespl: Vec<&str> = line.split('\t').collect();
let mut linechr: String = linespl[0].to_owned().to_string();
let mut linestart: String = linespl[1].to_owned().to_string();
let mut mval: String = linespl[2].to_owned().to_string();
if chr.is_empty(){
let chr = linechr;
methmap.insert(linestart, mval);
}else {
if chr == linechr{
methmap.insert(linestart, mval);
}else{
let mutmethmap: HashMap<String, String> = HashMap::new();
let chr = linechr;
methmap.insert(linestart, mval);
}
}
}
}
I am getting value borrowed here after move
error at first occurance of methmap
inside for loop. How do I resolve the issue?
I apologize is advance, I am quite new to the language.