Remove error foo from storage
This commit is contained in:
parent
3df9343412
commit
18ebf8ad83
1 changed files with 5 additions and 58 deletions
|
@ -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>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue