diff --git a/src/prehandle.rs b/src/prehandle.rs index 70c3a88..6eb93a6 100644 --- a/src/prehandle.rs +++ b/src/prehandle.rs @@ -1,8 +1,9 @@ use std::{io::Read, path::PathBuf}; use std::fs::File; use std::io::{BufRead, BufReader, Cursor}; +use std::ptr::read; -pub fn handle(path: PathBuf,filter_str:String, start_index: u32, end_index: u32) -> Box{ +pub fn handle(path: PathBuf, filter_str:String, start_index: u32, end_index: u32) -> Box{ let reader = BufReader::new(File::open(path).unwrap()); let mut lines = reader.lines().collect::, _>>().unwrap(); lines = filter_by_string(lines, filter_str.as_str()); @@ -22,6 +23,9 @@ fn filter_by_string(reader: Vec, filter_str: &str) ->Vec{ } fn take(reader: &mut Vec, start_index: u32, end_index: u32) -> Vec { + if end_index < 0 && start_index < 0{ + panic!("start_index and end_index must be positive"); + } if end_index == 0 && start_index == 0{ return reader.to_owned(); } @@ -30,8 +34,10 @@ fn take(reader: &mut Vec, start_index: u32, end_index: u32) -> Vec