Outsource file to string parsing
This commit is contained in:
parent
e0fefc3da4
commit
eabf726846
1 changed files with 4 additions and 16 deletions
|
@ -109,18 +109,7 @@ impl StorageBackend {
|
||||||
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
pub fn put_file<HP>(&self, f: File, p: &Parser<HP>) -> BackendOperationResult
|
||||||
where HP: FileHeaderParser
|
where HP: FileHeaderParser
|
||||||
{
|
{
|
||||||
let written = p.write(f.contents())
|
let written = write_with_parser(&f, p);
|
||||||
.or_else(|err| {
|
|
||||||
let mut serr = StorageBackendError::build(
|
|
||||||
"Parser::write()",
|
|
||||||
"Cannot parse file contents",
|
|
||||||
"Cannot translate internal representation of file contents into on-disk representation",
|
|
||||||
None
|
|
||||||
);
|
|
||||||
serr.caused_by = Some(&err);
|
|
||||||
Err(serr)
|
|
||||||
});
|
|
||||||
|
|
||||||
if written.is_err() { return Err(written.err().unwrap()); }
|
if written.is_err() { return Err(written.err().unwrap()); }
|
||||||
let string = written.unwrap();
|
let string = written.unwrap();
|
||||||
|
|
||||||
|
@ -306,17 +295,16 @@ impl<'a> Display for StorageBackendError<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, StorageBackendError>
|
fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, StorageBackendError<'a>> {
|
||||||
where HP: FileHeaderParser
|
|
||||||
{
|
|
||||||
p.write(f.contents())
|
p.write(f.contents())
|
||||||
.or_else(|err| {
|
.or_else(|err| {
|
||||||
let mut serr = StorageBackendError::build(
|
let mut serr = StorageBackendError::build(
|
||||||
"Parser::write()",
|
"Parser::write()",
|
||||||
|
"Cannot parse file contents",
|
||||||
"Cannot translate internal representation of file contents into on-disk representation",
|
"Cannot translate internal representation of file contents into on-disk representation",
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
serr.caused_by = Some(Box::new(err));
|
serr.caused_by = Some(&err);
|
||||||
Err(serr)
|
Err(serr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue