add: use BufReader for line by line reading

This commit is contained in:
2026-08-23 12:35:18 +05:30
parent dd48c9dfe3
commit 27cd5943a1
+10 -7
View File
@@ -1,22 +1,25 @@
#![allow(unused_imports)] #![allow(unused_imports)]
use std::env; use std::env;
use std::fs; use std::fs::File;
use std::io::{BufRead, BufReader};
use log::{debug, error, info, trace, warn}; use log::{debug, error, info, trace, warn};
use plume_log::{PlumeBuilder, success}; use plume_log::{PlumeBuilder, success};
fn main(){ fn main() -> std::io::Result<()>{
PlumeBuilder::new() PlumeBuilder::new()
.with_level(log::LevelFilter::Trace) .with_level(log::LevelFilter::Trace)
.init() .init()
.expect("Failed to init the logger"); .expect("Failed to init the logger");
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let file_path = &args[1]; info!("File: {}", &args[1]);
info!("{}", file_path); let file = File::open(&args[1])?;
let reader = BufReader::new(file);
let contents = fs::read_to_string(file_path) for line in reader.lines() {
.expect("File can't be read"); println!("+ {}", line?);
}
println!("{}", contents); Ok(())
} }