From b74e0f713f6fc05289649af7a9e3125db7720245 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jan 2016 14:06:55 +0100 Subject: [PATCH] Remove From for String and provide private helper for that functionality --- libimagstore/src/error.rs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index f29c3e17..9f6094a5 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -15,30 +15,17 @@ pub enum StoreErrorType { // maybe more } -impl From for String { - - fn from(e: StoreErrorType) -> String { - String::from(&e) +fn store_error_type_as_str(e: &StoreErrorType) -> &'static str { + match e { + &StoreErrorType::IdNotFound => "ID not found", + &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 { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - let s : String = self.into(); - try!(write!(fmt, "{:?}", s)); + try!(write!(fmt, "{:?}", store_error_type_as_str(self))); Ok(()) } @@ -47,8 +34,7 @@ impl Debug for StoreErrorType { impl Display for StoreErrorType { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - let s : String = self.into(); - try!(write!(fmt, "{}", s)); + try!(write!(fmt, "{}", store_error_type_as_str(self))); Ok(()) } @@ -91,8 +77,9 @@ impl Debug for StoreError { impl Display for StoreError { fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { - let e : String = self.err_type.clone().into(); - try!(write!(fmt, "[{}]: {}", e, self.expl)); + try!(write!(fmt, "[{}]: {}", + store_error_type_as_str(&self.err_type.clone()), + self.expl)); Ok(()) }