Skip to main content

cbor_core/value/
map.rs

1use std::collections::BTreeMap;
2
3use crate::{Error, Map, Result, Value};
4
5impl<'a> From<Map<'a>> for Value<'a> {
6    fn from(value: Map<'a>) -> Self {
7        Self::Map(value.into_inner())
8    }
9}
10
11impl<'a> From<BTreeMap<Value<'a>, Value<'a>>> for Value<'a> {
12    fn from(value: BTreeMap<Value<'a>, Value<'a>>) -> Self {
13        Self::Map(value)
14    }
15}
16
17impl<'a> TryFrom<Value<'a>> for BTreeMap<Value<'a>, Value<'a>> {
18    type Error = Error;
19    fn try_from(value: Value<'a>) -> Result<Self> {
20        value.into_map()
21    }
22}
23
24impl<'a> TryFrom<&'a Value<'a>> for &'a BTreeMap<Value<'a>, Value<'a>> {
25    type Error = Error;
26    fn try_from(value: &'a Value<'a>) -> Result<Self> {
27        value.as_map()
28    }
29}
30
31impl<'a> TryFrom<&'a mut Value<'a>> for &'a mut BTreeMap<Value<'a>, Value<'a>> {
32    type Error = Error;
33    fn try_from(value: &'a mut Value<'a>) -> Result<Self> {
34        value.as_map_mut()
35    }
36}
37
38impl<'a> TryFrom<Value<'a>> for Map<'a> {
39    type Error = Error;
40    fn try_from(value: Value<'a>) -> Result<Self> {
41        value.into_map().map(Map::from)
42    }
43}