Remove error foo from storage

This commit is contained in:
Matthias Beyer 2015-10-19 17:31:43 +02:00
parent 3df9343412
commit 18ebf8ad83

View file

@ -1,69 +1,16 @@
pub use std::path::Path; pub use std::path::Path;
pub use std::fs::File; pub use std::fs::File;
pub use std::error::Error;
pub use runtime::Runtime; pub use runtime::Runtime;
pub use error::ImagError;
pub use error::ImagErrorBase;
pub struct StorageError {
base : ImagErrorBase,
backendname : String,
}
impl StorageError {
pub fn new<T : StorageBackend>(backend : &T, short: String, long: String) -> StorageError {
StorageError {
base: ImagErrorBase {
shortdesc: short,
longdesc: long,
},
backendname: backend.name()
}
}
}
impl<'a> ImagError<'a> for StorageError {
fn print(&self, rt: &Runtime) {
if self.base.longdesc.is_empty() {
let s = format!("Backend {}: {}\n\n{}\n\n",
self.backendname,
self.base.shortdesc,
self.base.longdesc);
rt.print(&s)
} else {
let s = format!("Backend {}: {}\n",
self.backendname,
self.base.shortdesc);
rt.print(&s)
}
}
fn print_short(&self, rt : &Runtime) {
let s = format!("Backend {}: {}\n",
self.backendname,
self.base.shortdesc);
rt.print(&s)
}
fn print_long(&self, rt : &Runtime) {
let s = format!("Backend {}: {}\n\n{}\n\n",
self.backendname,
self.base.shortdesc,
self.base.longdesc);
rt.print(&s)
}
}
pub trait StorageBackend { pub trait StorageBackend {
fn name(&self) -> String; fn name(&self) -> String;
fn create(&self, file : File) -> Option<StorageError>; fn create(&self, file : File) -> Option<Error>;
fn read(&self, path: Path) -> Result<File, StorageError>; fn read(&self, path: Path) -> Result<File, Error>;
fn update(&self, file : File) -> Option<StorageError>; fn update(&self, file : File) -> Option<Error>;
fn destroy(&self, path: Path) -> Option<StorageError>; fn destroy(&self, path: Path) -> Option<Error>;
} }