Some simple Option / Result / iterator pattern simplifications (#3205)
This commit is contained in:
committed by
GitHub
parent
616dad43fd
commit
dcdbdd4bcc
+8
-11
@@ -70,15 +70,12 @@ fn copy_to(src: &Path, src_type: &fs::FileType, dst: &Path) -> io::Result<u64> {
|
||||
|
||||
/// Retrieve first line from file
|
||||
pub fn get_first_line(file_path: Option<String>) -> Option<String> {
|
||||
match file_path {
|
||||
Some(path) => match fs::File::open(path) {
|
||||
Ok(file) => {
|
||||
let buf_reader = io::BufReader::new(file);
|
||||
let mut lines_iter = buf_reader.lines().map(|l| l.unwrap());
|
||||
lines_iter.next()
|
||||
}
|
||||
Err(_) => None,
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
file_path.and_then(|path| match fs::File::open(path) {
|
||||
Ok(file) => {
|
||||
let buf_reader = io::BufReader::new(file);
|
||||
let mut lines_iter = buf_reader.lines().map(|l| l.unwrap());
|
||||
lines_iter.next()
|
||||
}
|
||||
Err(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user