Hello,
This is probably a stupid easy question but I have been able to solve it by googling yet.
I am reading in a txt file line by line using Bufreader then using that output to feed into a loop and using a crate called "distance" that calculates the hamming distance between to inputs. The problem I am running into is the the hamming function wants $str as input but the Bufreader is generating either a String or emun "result".
So basically how do I change a String to a $str
//collecting arguments
let args: Vec<String> = env::args().collect();
//assigning arguments to variables
let query = &args[1];
let file_path = &args[2];
//printing info about arguments
println!("Searching for {}", query);
println!("In file {}", file_path);
//assign file pathe to variable
let file = File::open(file_path).unwrap();
//put file into buffer
let reader = BufReader::new(file);
//iterate over buffer line by line
for line in reader.lines() {
println!("Line: {}", line.unwrap());
let distance = hamming(line_1, "ACTGATTC").unwrap();
println!("hamming distance: {}", distance)
}
The error output
error[E0308]: mismatched types
--> src/main.rs:29:32
|
29 | let distance = hamming(line, "ACTGATTC").unwrap();
| ------- ^^^^ expected `&str`, found enum `Result`
| |
| arguments to this function are incorrect
|
= note: expected reference `&str`
found enum `Result<String, std::io::Error>`
note: function defined here
--> /Users/joshua.hill/.cargo/registry/src/github.com-1ecc6299db9ec823/distance-0.4.0/src/hamming.rs:38:8
|
38 | pub fn hamming(s: &str, t: &str) -> Result<usize, DistanceError> {
| ^^^^^^^
Again this is probably a trivially easy thing to do but I cannot seem to get it. Learning a new language is hard.
Thanks for your time.