From 664260ef0d42b002b84dd85cea98d7109f1acc7c Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 4 Apr 2022 22:34:46 +0100 Subject: [PATCH] Enable internal conversion between values --- lib/src/sql/value/value.rs | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index e19e096f..3b67cba6 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -307,6 +307,12 @@ impl From for Value { } } +impl From for Value { + fn from(v: BigDecimal) -> Self { + Value::Number(Number::from(v)) + } +} + impl From for Value { fn from(v: String) -> Self { Value::Strand(Strand::from(v)) @@ -624,6 +630,42 @@ impl Value { msgpack::to_vec(&self).map_err(|e| e.into()) } + // ----------------------------------- + // Simple conversion of value + // ----------------------------------- + + pub fn make_bool(self) -> Value { + self.is_truthy().into() + } + + pub fn make_int(self) -> Value { + self.as_int().into() + } + + pub fn make_float(self) -> Value { + self.as_float().into() + } + + pub fn make_decimal(self) -> Value { + self.as_decimal().into() + } + + pub fn make_number(self) -> Value { + self.as_number().into() + } + + pub fn make_strand(self) -> Value { + self.as_strand().into() + } + + pub fn make_datetime(self) -> Value { + self.as_datetime().into() + } + + pub fn make_duration(self) -> Value { + self.as_duration().into() + } + // ----------------------------------- // Value operations // -----------------------------------