From 1f0c4e3107c50f52eab745d5572b957f5ccc359a Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 6 Dec 2017 12:29:11 -0800 Subject: [PATCH] Add common From coercions for TypedValue. --- core/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/core/src/lib.rs b/core/src/lib.rs index 73e28858..4fe71fd2 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -188,6 +188,50 @@ impl TypedValue { } } +// We don't do From or From 'cos it's ambiguous. + +impl From for TypedValue { + fn from(value: bool) -> TypedValue { + TypedValue::Boolean(value) + } +} + +impl From> for TypedValue { + fn from(value: DateTime) -> TypedValue { + TypedValue::Instant(value) + } +} + +impl From for TypedValue { + fn from(value: Uuid) -> TypedValue { + TypedValue::Uuid(value) + } +} + +impl From for TypedValue { + fn from(value: String) -> TypedValue { + TypedValue::String(Rc::new(value)) + } +} + +impl From for TypedValue { + fn from(value: NamespacedKeyword) -> TypedValue { + TypedValue::Keyword(Rc::new(value)) + } +} + +impl From for TypedValue { + fn from(value: u32) -> TypedValue { + TypedValue::Long(value as i64) + } +} + +impl From for TypedValue { + fn from(value: i32) -> TypedValue { + TypedValue::Long(value as i64) + } +} + // Put this here rather than in `db` simply because it's widely needed. pub trait SQLValueType { fn value_type_tag(&self) -> i32;