new to rust, I'm asking this to hopefully understand how to work with the language better..
Heres me trying to read a file, pass the file handle to a different function and print the lines from there:
use std::fs::File;
use std::io::{self, BufReader};
use std::io::BufRead;
use async_std::task;
async fn scrape<R: BufRead>(reader: &mut R) {
reader.lines().for_each(|line| println!(line));
}
fn main() -> io::Result<()> {
let file = File::open("wlist.txt")?;
let reader = BufReader::new(file);
// print_type_of(&reader); // prints std::io::buffered::BufReader<std::fs::File>
task::block_on(scrape(&mut reader));
Ok(())
}
// helper functions
fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}
Would love some insights regarding what concepts i'm missing and how this should be done properly !