From a9978fdcda04ec7d4f342c77d3eba4482bb0ba06 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 9 Feb 2022 08:50:05 +0000 Subject: [PATCH] Enable conversion to/from Vec for record values --- src/sql/value/value.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/sql/value/value.rs b/src/sql/value/value.rs index 2da461b2..2e79e557 100644 --- a/src/sql/value/value.rs +++ b/src/sql/value/value.rs @@ -386,6 +386,18 @@ impl From> for Value { } } +impl Into> for Value { + fn into(self) -> Vec { + serde_cbor::to_vec(&self).unwrap() + } +} + +impl From> for Value { + fn from(v: Vec) -> Self { + serde_cbor::from_slice::(&v).unwrap() + } +} + impl Value { // ----------------------------------- // Initial record value @@ -600,6 +612,10 @@ impl Value { .into() } + pub fn to_vec(&self) -> Result, Error> { + serde_cbor::to_vec(&self).map_err(|e| e.into()) + } + // ----------------------------------- // Value operations // -----------------------------------