I started with this code that just read every line in the file and works well:
use std::io::{BufRead, BufReader}; use std::fs::File; fn main() { let file = File::open("chry.fa").expect("cannot open file"); let file = BufReader::new(file); for line in file.lines() { print!("{}", line.unwrap()); } }
... but then I also tried to iterate over each character in each line, something like this:
use std::io::{BufRead, BufReader}; use std::fs::File; fn main() { let file = File::open("chry.fa").expect("cannot open file"); let file = BufReader::new(file); for line in file.lines() { for c in line.chars() { print!("{}", c.unwrap()); } } }
... but it turns out that this very inner loop is wrong. The following error message appears:
error[E0599]: no method named `chars` found for type `std::result::Result<std::string::String, std::io::Error>` in the current scope --> src/main.rs:8:23 | 8 | for c in line.chars() { | ^^^^^
source share