From f64f947f21d0ebfcd1fd27ae02b46e21c8654f0e Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 12 Jun 2021 17:16:14 +0800 Subject: [PATCH] Move code --- src/executor/query.rs | 86 +++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index e7da0604..d6c71ad6 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -23,6 +23,49 @@ pub trait TryGetable { Self: Sized; } +// QueryResult // + +impl QueryResult { + pub fn try_get(&self, pre: &str, col: &str) -> Result + where + T: TryGetable, + { + T::try_get(self, pre, col) + } +} + +// QueryErr // + +impl Error for QueryErr {} + +impl fmt::Display for QueryErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +impl From for QueryErr { + fn from(_: TypeErr) -> QueryErr { + QueryErr + } +} + +// TypeErr // + +impl Error for TypeErr {} + +impl fmt::Display for TypeErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +impl From for TypeErr { + fn from(_: sqlx::Error) -> TypeErr { + TypeErr + } +} + // TryGetable // macro_rules! try_getable { @@ -68,46 +111,3 @@ try_getable!(u64); try_getable!(f32); try_getable!(f64); try_getable!(String); - -// QueryResult // - -impl QueryResult { - pub fn try_get(&self, pre: &str, col: &str) -> Result - where - T: TryGetable, - { - T::try_get(self, pre, col) - } -} - -// QueryErr // - -impl Error for QueryErr {} - -impl fmt::Display for QueryErr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}", self) - } -} - -impl From for QueryErr { - fn from(_: TypeErr) -> QueryErr { - QueryErr - } -} - -// TypeErr // - -impl Error for TypeErr {} - -impl fmt::Display for TypeErr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}", self) - } -} - -impl From for TypeErr { - fn from(_: sqlx::Error) -> TypeErr { - TypeErr - } -}