异常处理
This commit is contained in:
parent
7cd9616cf6
commit
cb63a82646
@ -1,6 +1,7 @@
|
||||
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<dyn Read>{
|
||||
let reader = BufReader::new(File::open(path).unwrap());
|
||||
@ -22,6 +23,9 @@ fn filter_by_string(reader: Vec<String>, filter_str: &str) ->Vec<String>{
|
||||
}
|
||||
|
||||
fn take(reader: &mut Vec<String>, start_index: u32, end_index: u32) -> Vec<String> {
|
||||
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<String>, start_index: u32, end_index: u32) -> Vec<Strin
|
||||
body.push(header);
|
||||
if end_index == 0{
|
||||
body.append(&mut reader[start_index as usize..].to_owned());
|
||||
}else{
|
||||
}else if(end_index < reader.len() as u32){
|
||||
body.append(&mut reader[start_index as usize..end_index as usize].to_owned());
|
||||
}else {
|
||||
body.append(&mut reader[start_index as usize..].to_owned());
|
||||
}
|
||||
body
|
||||
}
|
Loading…
Reference in New Issue
Block a user