From c23a1e22ab8222ee1c1d4bf110f6c27677c730a3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 2 Dec 2015 11:44:31 +0100 Subject: [PATCH] Implement helper write_with_parser() --- src/storage/backend.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 12873509..e2cbd1c6 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -253,3 +253,18 @@ impl Display for StorageBackendError { } } + +fn write_with_parser<'a, HP>(f: &File, p: &Parser) -> Result + where HP: FileHeaderParser +{ + p.write(f.contents()) + .or_else(|err| { + let mut serr = StorageBackendError::build( + "Parser::write()", + "Cannot translate internal representation of file contents into on-disk representation", + None + ); + serr.caused_by = Some(Box::new(err)); + Err(serr) + }) +}