mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-27 03:51:38 +08:00
Impl From
for converting Value <-> BorrowedValue
This commit is contained in:
parent
5b0cdbaa56
commit
734f18c985
@ -11,16 +11,6 @@ pub enum BorrowedValue<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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<i64> {
|
pub fn as_i64(&self) -> Result<i64> {
|
||||||
match *self {
|
match *self {
|
||||||
BorrowedValue::Integer(i) => Ok(i),
|
BorrowedValue::Integer(i) => Ok(i),
|
||||||
@ -49,3 +39,27 @@ impl<'a> BorrowedValue<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<BorrowedValue<'a>> 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -55,6 +55,6 @@ impl<T: FromSql> FromSql for Option<T> {
|
|||||||
|
|
||||||
impl FromSql for Value {
|
impl FromSql for Value {
|
||||||
fn column_result(value: BorrowedValue) -> Result<Self> {
|
fn column_result(value: BorrowedValue) -> Result<Self> {
|
||||||
Ok(value.to_value())
|
Ok(value.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user