Parse Option<T> into Value/ValueRef where applicable

This commit is contained in:
Will Dowd 2019-09-27 16:02:37 -04:00
parent 104188055e
commit 49f48a5c56
2 changed files with 20 additions and 0 deletions

View File

@ -96,6 +96,16 @@ impl From<Vec<u8>> for Value {
}
}
impl <T> From<Option<T>> for Value
where T: Into<Value> {
fn from(v: Option<T>) -> Value {
match v {
Some(x) => x.into(),
None => Value::Null,
}
}
}
impl Value {
pub fn data_type(&self) -> Type {
match *self {

View File

@ -110,6 +110,16 @@ impl<'a> From<&'a Value> for ValueRef<'a> {
}
}
impl<'a, T> From<Option<T>> for ValueRef<'a>
where T: Into<ValueRef<'a>> {
fn from(s: Option<T>) -> 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> {