Remove From<StoreErrorType> for String and provide private helper for that functionality

This commit is contained in:
Matthias Beyer 2016-01-16 14:06:55 +01:00
parent 791995f8fc
commit b74e0f713f

View file

@ -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 {
fn from(e: StoreErrorType) -> String {
String::from(&e)
}
}
impl<'a> From<&'a StoreErrorType> for String {
fn from(e: &'a StoreErrorType) -> String {
match e { match e {
&StoreErrorType::IdNotFound => String::from("ID not found"), &StoreErrorType::IdNotFound => "ID not found",
&StoreErrorType::OutOfMemory => String::from("Out of Memory"), &StoreErrorType::OutOfMemory => "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(())
} }