diff --git a/core/src/lib.rs b/core/src/lib.rs index b70ec7e8..e87ccaf1 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -329,6 +329,78 @@ impl From for TypedValue { } } +impl TypedValue { + pub fn into_entid(self) -> Option { + match self { + TypedValue::Ref(v) => Some(v), + _ => None, + } + } + + pub fn into_kw(self) -> Option> { + match self { + TypedValue::Keyword(v) => Some(v), + _ => None, + } + } + + pub fn into_boolean(self) -> Option { + match self { + TypedValue::Boolean(v) => Some(v), + _ => None, + } + } + + pub fn into_long(self) -> Option { + match self { + TypedValue::Long(v) => Some(v), + _ => None, + } + } + + pub fn into_double(self) -> Option { + match self { + TypedValue::Double(v) => Some(v.into_inner()), + _ => None, + } + } + + pub fn into_instant(self) -> Option> { + match self { + TypedValue::Instant(v) => Some(v), + _ => None, + } + } + + pub fn into_timestamp(self) -> Option { + match self { + TypedValue::Instant(v) => Some(v.timestamp()), + _ => None, + } + } + + pub fn into_string(self) -> Option> { + match self { + TypedValue::String(v) => Some(v), + _ => None, + } + } + + pub fn into_uuid(self) -> Option { + match self { + TypedValue::Uuid(v) => Some(v), + _ => None, + } + } + + pub fn into_uuid_string(self) -> Option { + match self { + TypedValue::Uuid(v) => Some(v.hyphenated().to_string()), + _ => None, + } + } +} + /// Type safe representation of the possible return values from SQLite's `typeof` #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] pub enum SQLTypeAffinity {