Remove From<StoreErrorType> for String and provide private helper for that functionality
This commit is contained in:
parent
791995f8fc
commit
b74e0f713f
1 changed files with 9 additions and 22 deletions
|
@ -15,30 +15,17 @@ pub enum StoreErrorType {
|
||||||
// maybe more
|
// maybe more
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StoreErrorType> for String {
|
fn store_error_type_as_str(e: &StoreErrorType) -> &'static str {
|
||||||
|
match e {
|
||||||
fn from(e: StoreErrorType) -> String {
|
&StoreErrorType::IdNotFound => "ID not found",
|
||||||
String::from(&e)
|
&StoreErrorType::OutOfMemory => "Out of Memory",
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a StoreErrorType> for String {
|
|
||||||
|
|
||||||
fn from(e: &'a StoreErrorType) -> String {
|
|
||||||
match e {
|
|
||||||
&StoreErrorType::IdNotFound => String::from("ID not found"),
|
|
||||||
&StoreErrorType::OutOfMemory => String::from("Out of Memory"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for StoreErrorType {
|
impl Debug for StoreErrorType {
|
||||||
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
||||||
let s : String = self.into();
|
try!(write!(fmt, "{:?}", store_error_type_as_str(self)));
|
||||||
try!(write!(fmt, "{:?}", s));
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +34,7 @@ impl Debug for StoreErrorType {
|
||||||
impl Display for StoreErrorType {
|
impl Display for StoreErrorType {
|
||||||
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
||||||
let s : String = self.into();
|
try!(write!(fmt, "{}", store_error_type_as_str(self)));
|
||||||
try!(write!(fmt, "{}", s));
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +77,9 @@ impl Debug for StoreError {
|
||||||
impl Display for StoreError {
|
impl Display for StoreError {
|
||||||
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> {
|
||||||
let e : String = self.err_type.clone().into();
|
try!(write!(fmt, "[{}]: {}",
|
||||||
try!(write!(fmt, "[{}]: {}", e, self.expl));
|
store_error_type_as_str(&self.err_type.clone()),
|
||||||
|
self.expl));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue