Merge pull request #571 from dowdw/from-option

Parse Option<T> into Value/ValueRef where applicable
This commit is contained in:
gwenn 2019-10-09 19:50:19 +02:00 committed by GitHub
commit 2d75411e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 { impl Value {
pub fn data_type(&self) -> Type { pub fn data_type(&self) -> Type {
match *self { 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"))] #[cfg(any(feature = "functions", feature = "session", feature = "vtab"))]
impl<'a> ValueRef<'a> { impl<'a> ValueRef<'a> {
pub(crate) unsafe fn from_value(value: *mut crate::ffi::sqlite3_value) -> ValueRef<'a> { pub(crate) unsafe fn from_value(value: *mut crate::ffi::sqlite3_value) -> ValueRef<'a> {