diff --git a/src/types/borrowed_value.rs b/src/types/borrowed_value.rs index 8b97a33..cbbb977 100644 --- a/src/types/borrowed_value.rs +++ b/src/types/borrowed_value.rs @@ -11,16 +11,6 @@ pub enum BorrowedValue<'a> { } impl<'a> BorrowedValue<'a> { - pub fn to_value(&self) -> Value { - match *self { - BorrowedValue::Null => Value::Null, - BorrowedValue::Integer(i) => Value::Integer(i), - BorrowedValue::Real(r) => Value::Real(r), - BorrowedValue::Text(s) => Value::Text(s.to_string()), - BorrowedValue::Blob(b) => Value::Blob(b.to_vec()), - } - } - pub fn as_i64(&self) -> Result { match *self { BorrowedValue::Integer(i) => Ok(i), @@ -49,3 +39,27 @@ impl<'a> BorrowedValue<'a> { } } } + +impl<'a> From> for Value { + fn from(borrowed: BorrowedValue) -> Value { + match borrowed { + BorrowedValue::Null => Value::Null, + BorrowedValue::Integer(i) => Value::Integer(i), + BorrowedValue::Real(r) => Value::Real(r), + BorrowedValue::Text(s) => Value::Text(s.to_string()), + BorrowedValue::Blob(b) => Value::Blob(b.to_vec()), + } + } +} + +impl<'a> From<&'a Value> for BorrowedValue<'a> { + fn from(value: &'a Value) -> BorrowedValue<'a> { + match *value { + Value::Null => BorrowedValue::Null, + Value::Integer(i) => BorrowedValue::Integer(i), + Value::Real(r) => BorrowedValue::Real(r), + Value::Text(ref s) => BorrowedValue::Text(s), + Value::Blob(ref b) => BorrowedValue::Blob(b), + } + } +} diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index a996347..c733f07 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -55,6 +55,6 @@ impl FromSql for Option { impl FromSql for Value { fn column_result(value: BorrowedValue) -> Result { - Ok(value.to_value()) + Ok(value.into()) } }