From 49f48a5c56faf9d03943d36898b93725f6ad3304 Mon Sep 17 00:00:00 2001 From: Will Dowd Date: Fri, 27 Sep 2019 16:02:37 -0400 Subject: [PATCH] Parse Option into Value/ValueRef where applicable --- src/types/value.rs | 10 ++++++++++ src/types/value_ref.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/types/value.rs b/src/types/value.rs index 8a2fffe..00295e7 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -96,6 +96,16 @@ impl From> for Value { } } +impl From> for Value + where T: Into { + fn from(v: Option) -> Value { + match v { + Some(x) => x.into(), + None => Value::Null, + } + } +} + impl Value { pub fn data_type(&self) -> Type { match *self { diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index 9a48bcf..acc9aa6 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -110,6 +110,16 @@ impl<'a> From<&'a Value> for ValueRef<'a> { } } +impl<'a, T> From> for ValueRef<'a> + where T: Into> { + fn from(s: Option) -> ValueRef<'a> { + match s { + Some(x) => x.into(), + None => ValueRef::Null, + } + } +} + #[cfg(any(feature = "functions", feature = "session", feature = "vtab"))] impl<'a> ValueRef<'a> { pub(crate) unsafe fn from_value(value: *mut crate::ffi::sqlite3_value) -> ValueRef<'a> {