From 2ed2b17b857b845a8f89f8a810ce24b9eeab5b3d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Nov 2015 16:46:09 +0100 Subject: [PATCH] Refactor get_file_by_id() into smaller functions --- src/storage/backend.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/storage/backend.rs b/src/storage/backend.rs index d3590097..9dd0de4a 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -124,18 +124,10 @@ impl StorageBackend { pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser) -> Option where HP: FileHeaderParser<'a> { - let path = self.build_filepath_with_id(id); - if let Ok(file) = FSFile::open(path) { + if let Ok(fs) = FSFile::open(self.build_filepath_with_id(id)) { let mut s = String::new(); - file.read_to_string(&mut s); - let parser_out = p.read(s); - if let Ok((header, data)) = parser_out { - Some(File::from_parser_result(id, header, data)) - } else { - info!("Cannot build File from ID '{}'. Parser Error:\n{}", - id, parser_out.err().unwrap()); - None - } + fs.read_to_string(&mut s); + p.read(s).and_then(|(h, d)| Ok(File::from_parser_result(id, h, d))).ok() } else { None }