Enable conversion to/from Vec<u8> for record values

This commit is contained in:
Tobie Morgan Hitchcock 2022-02-09 08:50:05 +00:00
parent 811064bb05
commit a9978fdcda

View file

@ -386,6 +386,18 @@ impl From<Option<String>> for Value {
}
}
impl Into<Vec<u8>> for Value {
fn into(self) -> Vec<u8> {
serde_cbor::to_vec(&self).unwrap()
}
}
impl From<Vec<u8>> for Value {
fn from(v: Vec<u8>) -> Self {
serde_cbor::from_slice::<Value>(&v).unwrap()
}
}
impl Value {
// -----------------------------------
// Initial record value
@ -600,6 +612,10 @@ impl Value {
.into()
}
pub fn to_vec(&self) -> Result<Vec<u8>, Error> {
serde_cbor::to_vec(&self).map_err(|e| e.into())
}
// -----------------------------------
// Value operations
// -----------------------------------